Windows 10 Pro + VsCode + PHP で xdebug を設定してみる

Windows 10 Pro + VsCode + PHPxdebug を設定してみる

Windows Server + php5.6環境にXdebugを導入
VsCodeの 拡張機能 PHP Debug Adapter for Visual Studio Code のドキュメント
Windows 10 Pro + VsCode で PHP を使ってみる
( を使用)
より php_xdebug-2.6.0-7.2-vc15-x86_64.dll をDLする
ntsの場合は php_xdebug-2.6.0-7.2-vc15-nts-x86_64.dll
ダウンロードしたdllを /path/to/\php7\ext に配置する
php.ini に以下を追加する
zend_extension = /path/to\php7\ext\php_xdebug-2.6.0-7.2-vc15-x86_64.dll
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
WebServer(IIS) を再起動後 phpinfo() で以下が確認できる
This program makes use of the Zend Scripting Language Engine:
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans;<-追加される
xdebug セクション;<-追加される
PHP Debug

launch.json が未定義の場合(作成後でも メニュー->デバッグの開始 を実行しないと以下の結果になる)

[Running] php "d:\Dev\php\0002.php"
日本語PHP Notice: Undefined variable: p in D:\Dev\php\0002.php on line 3
PHP Stack trace:
PHP 1. {main}() D:\Dev\php\0002.php:0

[Done] exited with code=0 in 0.554 seconds

メニュー->デバッグの開始->php を選択すると launch.json が(初回のみ)作成される
// IntelliSense を使用して利用可能な属性を学べます。
// 既存の属性の説明をホバーして表示します。
// 詳細情報は次を確認してください:
"version": "0.2.0",
"configurations": [
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
メニュー->デバッグの開始 を選択後 run code(Code Runner) を実行すると
firewall に登録するかのダイアログが初回のみ表示されます


Notice: Undefined variable: p

remoto 等使い方は、研究中
以下 PHP Debug 1.12.2 のドキュメントのコピペ
Supported launch.json settings:
request: Always "launch"
port: The port on which to listen for XDebug (default: 9000)
stopOnEntry: Wether to break at the beginning of the script (default: false)
pathMappings: A list of server paths mapping to the local source paths on your machine, see "Remote Host Debugging" below
log: Wether to log all communication between VS Code and the adapter to the debug console. See Troubleshooting further down.
ignore: An optional array of glob patterns that errors should be ignored from (for example **/vendor/**/*.php)
xdebugSettings: Allows you to override XDebug's remote debugging settings to fine tuning XDebug to your needs. For example, you can play with max_children and max_depth to change the max number of array and object children that are retrieved and the max depth in structures like arrays and objects. This can speed up the debugger on slow machines. For a full list of feature names that can be set please refer to the XDebug documentation.
max_children: max number of array or object children to initially retrieve
max_data: max amount of variable data to initially retrieve.
max_depth: maximum depth that the debugger engine may return when sending arrays, hashs or object structures to the IDE.
show_hidden: This feature can get set by the IDE if it wants to have more detailed internal information on properties (eg. private members of classes, etc.) Zero means that hidden members are not shown to the IDE.
Options specific to CLI debugging:
program: Path to the script that should be launched
args: Arguments passed to the script
cwd: The current working directory to use when launching the script
runtimeExecutable: Path to the PHP binary used for launching the script. By default the one on the PATH.
runtimeArgs: Additional arguments to pass to the PHP binary
externalConsole: Launches the script in an external console window instead of the debug console (default: false)
env: Environment variables to pass to the script
Line breakpoints
Conditional breakpoints
Function breakpoints
Step over, step in, step out
Break on entry
Breaking on uncaught exceptions and errors / warnings / notices
Multiple, parallel requests
Stack traces, scope variables, superglobals, user defined constants
Arrays & objects (including classname, private and static properties)
Debug console
Run as CLI
Run without debugging
Remote Host Debugging
To debug a running application on a remote host, you need to tell XDebug to connect to a different IP than localhost. This can either be done by setting xdebug.remote_host to your IP or by setting xdebug.remote_connect_back = 1 to make XDebug always connect back to the machine who did the web request. The latter is the only setting that supports multiple users debugging the same server and "just works" for web projects. Again, please see the XDebug documentation on the subject for more information.
To make VS Code map the files on the server to the right files on your local machine, you have to set the pathMappings settings in your launch.json. Example:
// server -> local
"pathMappings": {
"/var/www/html": "${workspaceRoot}/www",
"/app": "${workspaceRoot}/app"
Please also note that setting any of the CLI debugging options will not work with remote host debugging, because the script is always launched locally. If you want to debug a CLI script on a remote host, you need to launch it manually from the command line.
Ask a question on Gitter
If you think you found a bug, open an issue
Make sure you have the latest version of this extension and XDebug installed
Try out a simple PHP file to recreate the issue, for example from the testproject
In your php.ini, set xdebug.remote_log = /path/to/logfile (make sure your webserver has write permissions to the file)
Set "log": true in your launch.json
To hack on this adapter, clone the repository and open it in VS Code. You need NodeJS and typings installed (npm install -g typings). Install dependencies by running npm install and typings install.
You can debug the extension (run it in "server mode") by selecting the "Debug adapter" launch configuration and hitting F5. Then, open a terminal inside the project, and open the included testproject with VS Code while specifying the current directory as extensionDevelopmentPath:
code testproject --extensionDevelopmentPath=.
VS Code will open an "Extension Development Host" with the debug adapter running. Open .vscode/launch.json and uncomment the debugServer configuration line. Hit F5 to start a debugging session. Now you can debug the testproject like specified above and set breakpoints inside your first VS Code instance to step through the adapter code.
The extension is written in TypeScript and compiled using a Gulpfile that first transpiles to ES6 and then uses Babel to specifically target VS Code's Node version. You can run the compile task through npm run compile, gulp compile or from VS Code with Ctrl+Shift+B. npm run watch / gulp watch enables incremental compilation.
Tests are written with Mocha and can be run with npm test. The tests are run in CI on Linux and Windows against PHP 5.4, 5.6, 7.0 and XDebug 2.3, 2.4.