{"id":532,"date":"2023-10-28T23:59:12","date_gmt":"2023-10-28T14:59:12","guid":{"rendered":"https:\/\/web.cloudfree.jp\/journal\/?p=532"},"modified":"2024-02-01T12:41:08","modified_gmt":"2024-02-01T03:41:08","slug":"php-debug%e7%92%b0%e5%a2%83%e3%81%ae%e6%a7%8b%e7%af%89-xdebug","status":"publish","type":"post","link":"https:\/\/web.cloudfree.jp\/journal\/php-debug%e7%92%b0%e5%a2%83%e3%81%ae%e6%a7%8b%e7%af%89-xdebug\/","title":{"rendered":"PHP \u30c7\u30d0\u30c3\u30b0\u74b0\u5883\u306e\u69cb\u7bc9 XDebug"},"content":{"rendered":"<h3 style=\"padding-top:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20);\" class=\"wp-block-post-title\">PHP \u30c7\u30d0\u30c3\u30b0\u74b0\u5883\u306e\u69cb\u7bc9 XDebug<\/h3>\n\n\n<p class=\"has-tertiary-color has-text-color has-background has-small-font-size\" style=\"background-color:#8d8dd8;margin-top:0;margin-right:0;margin-bottom:0;margin-left:0;padding-top:0;padding-right:0;padding-bottom:0;padding-left:0\">2023-10-28 \u8a18\u8f09<br>\u6982\u8981\uff1aXDebug\u3092\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u3057\u305f\u3089\u7d71\u5408\u958b\u767a\u74b0\u5883\u306a\u307f\u306e\u30c7\u30d0\u30c3\u30b0\u74b0\u5883\u304cPHP\u3067\u3082\u5f97\u3089\u308c\u308b<br>Keyword : XDebug, PHP, VisualStudioCode, <\/p>\n\n\n\n<p>PHP\u306e\u30ed\u30b8\u30c3\u30af\u306f\u305f\u3044\u3066\u3044\u5024\u3092\u307f\u3066\u3001\u305d\u306e\u5024\u6b21\u7b2c\u3067\u3001\u5024\u3092\u53f3\u304b\u3089\u5de6\u3078\u6e21\u3059\u3060\u3051\u3002\u3068\u304d\u306b\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u5909\u3048\u305f\u308a\u3059\u308b\u3050\u3089\u3044\u3002\u8907\u96d1\u306a\u30ed\u30b8\u30c3\u30af\u306f\u4f7f\u308f\u306a\u3044\u304b\u3089var_dump()\u3067\u305f\u3044\u3066\u3044\u30c7\u30d0\u30c3\u30b0\u3067\u304d\u307e\u3059\u304c\u3001\u3084\u306f\u308a\u30b9\u30c6\u30c3\u30d7\u5b9f\u884c\u3068\u5909\u6570\u30a6\u30a9\u30c3\u30c1\u306e\u3067\u304d\u308b\u30c7\u30d0\u30c3\u30b0\u74b0\u5883\u304c\u3042\u308c\u3070\u5feb\u9069\u3067\u52b9\u7387\u7684\u3067\u3059\u3002<br><br><strong>[Step1]VSCode\u306bPHP Debug\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1014\" height=\"606\" src=\"https:\/\/web.cloudfree.jp\/journal\/wp-content\/uploads\/2023\/10\/phpdebug.jpg\" alt=\"\" class=\"wp-image-533\" srcset=\"https:\/\/web.cloudfree.jp\/journal\/wp-content\/uploads\/2023\/10\/phpdebug.jpg 1014w, https:\/\/web.cloudfree.jp\/journal\/wp-content\/uploads\/2023\/10\/phpdebug-300x179.jpg 300w, https:\/\/web.cloudfree.jp\/journal\/wp-content\/uploads\/2023\/10\/phpdebug-768x459.jpg 768w\" sizes=\"(max-width: 1014px) 100vw, 1014px\" \/><\/figure>\n\n\n\n<p><strong>[Step2]VSCode\u306e\u8a2d\u5b9a<\/strong><br>PHP IntelliSense\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3042\u308c\u3070<br>&#8220;php.validate.executablePath&#8221;: &#8220;C:\\\\pgm\\\\php8\\\\php.exe&#8221;,<br>&#8220;php.debug.executablePath&#8221;: &#8220;C:\\\\pgm\\\\php8\\\\php.exe&#8221;,<br>\u306e\uff12\u884c\u306f\u8a18\u8ff0\u6e08\u307f\u3067\u305d\u3053\u3078\u8ffd\u52a0\u3057\u307e\u3059\u3002\u203b\u30d1\u30b9\u306f\u74b0\u5883\u6b21\u7b2c<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\" data-file=\"VSCode\u306e\u57fa\u672c\u8a2d\u5b9a\"><code>&quot;php.validate.executablePath&quot;: &quot;C:\\\\pgm\\\\php8\\\\php.exe&quot;,\n&quot;php.debug.executablePath&quot;: &quot;C:\\\\pgm\\\\php8\\\\php.exe&quot;,\n&quot;php.validate.enable&quot;: false,\n&quot;php.suggest.basic&quot;: false,    \n&quot;launch&quot;: {\n    &quot;configurations&quot;: [{\n        &quot;name&quot;: &quot;Listen for Xdebug&quot;,\n        &quot;type&quot;: &quot;php&quot;,\n        &quot;request&quot;: &quot;launch&quot;,\n        &quot;port&quot;: 9000\n    }]\n},<\/code><\/pre><\/div>\n\n\n\n<p><strong>[Step3]php_xdebug.dll\u306e\u53d6\u5f97<\/strong><br>Windows\u7528\u306eDownload\u30da\u30fc\u30b8\u306f\u4ee5\u4e0b\u3002<br><a rel=\"noreferrer noopener\" href=\"https:\/\/xdebug.org\/download\" target=\"_blank\">https:\/\/xdebug.org\/download<\/a><br>PHP\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3001TS\u306f\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u3001OS\u306b\u3042\u3063\u305fWindows binaries\u3092\u53d6\u5f97\u3002<br>\u201dphp_xdebug-*.dll\u201d<br>\u3092Download\u3057\u305f\u3089<br>C:\\pgm\\php8\\ext\\ \u306b\u914d\u7f6e\u3002<br>\u203b\u81ea\u5206\u304c\u4f55\u3092\u5165\u308c\u3066\u3044\u308b\u306e\u304b\u308f\u304b\u3063\u305f\u307b\u3046\u304c\u3088\u3044\u304b\u3089php_xdebug.dll\u306b\u30ea\u30cd\u30fc\u30e0\u306f\u305b\u305a\u306b<br>\u3000\u4ee5\u4e0b\u306ephp.ini\u3068\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u3042\u308f\u305b\u308b\u65b9\u6cd5\u304c\u30d9\u30bf\u30fc<\/p>\n\n\n\n<p><strong>[Step4]php.ini\u306b\u8a2d\u5b9a\u8ffd\u52a0<\/strong><br>(\u3069\u3053\u3067\u3082\u3044\u3044\u3051\u3069; Module Settings ; \u306e\u5148\u982d\u3042\u305f\u308a)<br>[XDebug]<br>zend_extension = &#8220;C:\\pgm\\php8\\ext\\php_xdebug-3.3.0alpha3-8.2-vs16-x86_64.dll&#8221;<br>xdebug.mode=debug<br>xdebug.start_with_request = yes<br>xdebug.client_host=127.0.0.1<br>xdebug.client_port=9000<br>xdebug.log_level=0<\/p>\n\n\n\n<p class=\"has-background\" style=\"background-color:#ffffbb\">\u3010\u6ce8\u610f: 2023.11.8\u8ffd\u8a18\u3011<br>xdebug.start_with_request = yes<br>\u3068\u66f8\u304f\u3068\u30b3\u30f3\u30bd\u30fc\u30eb\u5b9f\u884c(DOS\u7a93\u306a\u3069\u304b\u3089)\u3055\u305b\u305f\u3068\u304d\u4ee5\u4e0b\u306e\u8868\u793a\u304c\u51fa\u3066\u5b9f\u884c\u3055\u308c\u306a\u304f\u306a\u308a\u307e\u3059\u3002<br><br>Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: 127.0.0.1:9000 (through xdebug.client_host\/xdebug.client_port).<br>The process cannot access the file because it is being used by another process.<br><br>\u3053\u308c\u306f\u307e\u305a\u3044\u306e\u3067\u56de\u907f\u7b56\u3068\u3055\u308c\u3066\u3044\u308b<br>xdebug.start_with_request = trigger<br>\u306b\u3059\u308b\u3068\u30b3\u30f3\u30bd\u30fc\u30eb\u5b9f\u884c\u304b\u3089\u306f\u30a8\u30e9\u30fc\u7121\u3057\u3067\u3059\u304c\u3001\u3057\u304b\u3057VSCode\u3067\u6b62\u307e\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002<br>settingJSON\u3068php.ini\u305d\u308c\u305e\u308c\u3069\u3046\u66f8\u3051\u3070\u4e21\u7acb\u3059\u308b\u306e\u304b\u3001\u306f\u5f8c\u65e5\u306e\u8abf\u67fb\u8ab2\u984c\u3068\u3057\u3066\u3001\u3068\u308a\u3042\u3048\u305a\u306e\u89e3\u6c7a\u7b56\u304c\u3053\u308c\u3002<br><br>xdebug.start_with_request = yes<br>xdebug.log_level=0<br><br>\u3092\u30bb\u30c3\u30c8\u3067\u3044\u308c\u308b\u3068\u4e21\u7acb\u3057\u307e\u3057\u305f\u3002<br>\u305f\u3060\u3057PHP\u51e6\u7406\u306b\u6052\u5e38\u7684\u306b\u8ca0\u8377\u304c\u304b\u304b\u308a\u305d\u3046\u3067\u3001\uff11\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\uff11\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u306e\uff11\u4eba\u4f7f\u3044\u306e\u958b\u767a\u74b0\u5883\u30de\u30b7\u30f3\u306a\u3089\u3067\u306f\u306e\u8a2d\u5b9a\u3060\u3068\u601d\u3044\u307e\u3059\u3002<br>PHP\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u30ad\u30fc\u30d7\u3059\u308b\u306a\u3089\u3001\u3081\u3063\u305f\u306b\u4f7f\u308f\u306a\u3044VSCode\u306eStepin-Debug\u306e\u3068\u304d\u3060\u3051\u3001yes\u306b\u6bce\u5ea6\u66f8\u304d\u63db\u3048\u308b\u306e\u304c\u3088\u3044\u304b\u3082\u3067\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>\u30c6\u30b9\u30c8<\/strong><br>C:\\pgm\\Apache24\\htdocs<br>\u306btest.php\u3092\u4f5c\u6210\u3057\u3066 http:\/\/localhost\/test.php \u3067\u958b\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-php\" data-file=\"test.php\" data-lang=\"PHP\"><code>Hello PHP Debug.&lt;br&gt;\n&lt;?php\n$flag = false;\n$count = 1;\ndo {\n    echo &quot;count = $count&lt;br&gt;&quot;;\n    if ($flag) {\n        $count = $count - 3;\n    } else {\n        $count++;\n    }\n} while ($count &gt; 0 && $count &lt; 10);\n\necho &quot;count = $count&lt;br&gt;&quot;;\n?&gt;<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-plain\" data-file=\"\u5b9f\u884c\u7d50\u679c\"><code>Hello PHP Debug.\ncount = 1\ncount = 2\ncount = 3\ncount = 4\ncount = 5\ncount = 6\ncount = 7\ncount = 8\ncount = 9<\/code><\/pre><\/div>\n\n\n\n<p>7\u884c\u76ee\u306e<br>\u25cf if ($flag) {<br>\u306b\u30d6\u30ec\u30fc\u30af\u30dd\u30a4\u30f3\u30c8\u3092\u4ed8\u3051\u3066\u3001[ F5 ]\u30c7\u30d0\u30c3\u30b0\u306e\u958b\u59cb\u3002<br>\u30d6\u30e9\u30a6\u30b6\u306e\u30ea\u30ed\u30fc\u30c9\u3067\u30bf\u30b9\u30af\u30d0\u30fc\u306eVSC\u304c\u30d5\u30e9\u30c3\u30b7\u30e5\u3059\u308c\u3070\u8a2d\u5b9a\u306f\u6210\u529f\u3002<br>[ F10 ]\u30b9\u30c6\u30c3\u30d7\u30aa\u30fc\u30d0\u30fc\u3067\u30eb\u30fc\u30d7\uff16\u5468\u307b\u3069\u3057\u3066\u304b\u3089<br>\u5de6\u30da\u30a4\u30f3\u306e$flag\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u5024\u3092false\u304b\u3089true\u3078\u66f8\u304d\u63db\u3048\u3002<br>$count = $count &#8211; 3;<br>\u306b\u51e6\u7406\u304c\u5165\u308b\u3088\u3046\u306b\u306a\u308a\u3001\u5b9f\u884c\u7d50\u679c\u3082\u5909\u308f\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"514\" height=\"361\" src=\"https:\/\/web.cloudfree.jp\/journal\/wp-content\/uploads\/2023\/10\/phpdebug2.jpg\" alt=\"\" class=\"wp-image-534\" srcset=\"https:\/\/web.cloudfree.jp\/journal\/wp-content\/uploads\/2023\/10\/phpdebug2.jpg 514w, https:\/\/web.cloudfree.jp\/journal\/wp-content\/uploads\/2023\/10\/phpdebug2-300x211.jpg 300w\" sizes=\"(max-width: 514px) 100vw, 514px\" \/><\/figure>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-plain\" data-file=\"\u5b9f\u884c\u7d50\u679c\"><code>Hello PHP Debug.\ncount = 1\ncount = 2\ncount = 3\ncount = 4\ncount = 5\ncount = 6\ncount = 3\ncount = 0<\/code><\/pre><\/div>\n\n\n\n<p>Excel VBA\u306e\u30c7\u30d0\u30c3\u30b0\u306e\u3088\u3046\u306b\u30c4\u30de\u30df\u3092D&amp;D\u3057\u3066\u597d\u304d\u306a\u3068\u3053\u308d\u304b\u3089\u51e6\u7406\u958b\u59cb<br>\u3068\u3044\u3046\u306e\u306f\u3055\u3059\u304c\u306b\u7121\u7406\u307f\u305f\u3044\u3067\u3059\u304c\u3001\u3053\u308c\u3060\u3051\u51fa\u6765\u305f\u3089\u3058\u3085\u3046\u3076\u3093\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"has-text-align-left has-black-color has-text-color has-background\" style=\"background-color:#f8c8d5;margin-right:0;margin-left:0;padding-top:0;padding-right:0;padding-bottom:0;padding-left:0\">2024-02-01 \u8ffd\u8a18<br>php.ini\u306e[XDebug]\u30bb\u30af\u30b7\u30e7\u30f3\u306e\u8a2d\u5b9a\u306f\u306a\u304b\u306a\u304b\u96e3\u3057\u3044\u3088\u3046\u3067\u3001CPU\u4f7f\u7528\u7387\u3092100%\u306b\u3057\u3066\u3057\u307e\u3046Apache\u306e\u30d7\u30ed\u30bb\u30b9\u6b8b\u308a\u304c\u5f8c\u65e5\u78ba\u8a8d\u3055\u308c\u307e\u3057\u305f\u3002<br>\u4ee5\u4e0b\u306e\u6295\u7a3f\u3082\u3042\u308f\u305b\u3066\u3054\u53c2\u7167\u304f\u3060\u3055\u3044\u3002<br><br><a href=\"https:\/\/web.cloudfree.jp\/journal\/php%e3%81%aexdebug%e3%81%8ccpu%e4%bd%bf%e7%94%a8%e7%8e%87100%e3%81%ab%e3%81%99%e3%82%8b\/\" data-type=\"post\" data-id=\"889\">PHP\u306e[XDebug]\u304cCPU\u4f7f\u7528\u7387100%\u306b\u3059\u308b<\/a><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Excel VBA\u306e\u30c7\u30d0\u30c3\u30b0\u306e\u3088\u3046\u306b\u30c4\u30de\u30df\u3092D&#038;D\u3057\u3066\u597d\u304d\u306a\u3068\u3053\u308d\u304b\u3089\u51e6\u7406\u958b\u59cb\u3068\u3044\u3046\u306e\u306f\u3055\u3059\u304c\u306b\u7121\u7406\u307f\u305f\u3044\u3067\u3059\u304c\u3001\u3053\u308c\u3060\u3051\u51fa\u6765\u305f\u3089\u3058\u3085\u3046\u3076\u3093\u3067\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":535,"comment_status":"open","ping_status":"closed","sticky":false,"template":"wp-custom-template-x24-index","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[21,23,28,47,14,48,24],"_links":{"self":[{"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/posts\/532"}],"collection":[{"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/comments?post=532"}],"version-history":[{"count":0,"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/posts\/532\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/media\/535"}],"wp:attachment":[{"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/media?parent=532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/categories?post=532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/tags?post=532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}