我尝试使用VSCode(VSCcode版本1.9.1)配置xdebug。
php.ini
[Xdebug]
zend_extension = D:\php\ext\php_xdebug.dll
xdebug.remote_autostart = 1
xdebug.remote_enable = 1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
xdebug.remote_log = D:\site\xlog.txt
我的默认php端口是3000. ($_SERVER['SERVER_PORT'] = 3000
我可以在phpinfo()
实际运行localhost:3000
和Xdebug端口设置为xdebug.remote_port = 9000
Xdebug日志:
Log opened at 2017-02-17 20:50:56
I: Connecting to configured address/port: localhost:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///D:/site/index.php" language="PHP" xdebug:language_version="7.1.0-dev" protocol_version="1.0" appid="11384" idekey="Admin"><engine version="2.5.0"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2016 by Derick Rethans]]></copyright></init>
<- breakpoint_list -i 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="1"></response>
<- breakpoint_list -i 2
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="2"></response>
<- breakpoint_set -i 3 -t exception -x *
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="3" id="113840001"></response>
<- run -i 4
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="4" status="stopping" reason="ok"></response>
<- stop -i 5
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="stop" transaction_id="5" status="stopped" reason="ok"></response>
Log closed at 2017-02-17 20:50:56
launch.json:
{
"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
}
]
}
对于以下测试代码:
$var = "test\n";
print $var;
var_dump($var);
我在调试控制台中得到了这个:
test D:\site\index.php:5: string(5) "test "
但是调试列表中的无变量 ..
我不知道为什么,但变量不会出现在VSCode中。
当我尝试到达localhost:3000
时...这就是我得到的:
Log opened at 2017-02-17 21:38:16
I: Connecting to configured address/port: localhost:9000.
E: Time-out connecting to client. :-(
Log closed at 2017-02-17 21:38:17
答案 0 :(得分:1)
让它工作(仅使用php版本7进行测试)。
vscode&gt; debug&gt;齿轮图标&gt; launch.json
{
"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
}
]
}
vscode&gt;文件&gt;首选项&gt; settings.json&gt;工作空间设置
// Place your settings in this file to overwrite default and user settings.
{
"php.validate.executablePath": "C:\\Program Files (x86)\\php\\php7\\php.exe",
"php.validate.enable":true
}
php.ini 将此添加到文件末尾(注意&#34; zend_extension&#34;中没有路径斜杠)
[Xdebug]
zend_extension = php_xdebug-2.5.4-7.0-vc14-nts.dll
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_log = C:\Temp\Xdebug_log.txt
也请观看此YouTube指南:
最后,配置完成后,以下是如何在vs代码中使用调试器来显示变量,watch,callstack:
答案 1 :(得分:0)
您需要将主机端口更改为3000
请按照以下步骤操作:
vscode>调试>齿轮图标> launch.json
{
"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": 3000
}
]
}
这对我有用
答案 2 :(得分:0)
我遇到了类似的问题-您提供的相同日志条目,相同症状,几乎相同的配置。 XDebug在上周的一天突然对我失败,并且所有局部变量开始显示为“未定义”,没有弹出检查等。在我拥有的几乎完全相同的另一台主机上调试相同的代码仍然可以正常工作。
在卸载并重新安装XDebug并多次尝试VSCode扩展并尝试了许多配置更改后,我最终发现问题是由放置在监视列表中的表达式引起的。从我的监视列表中删除有问题的表达式后(在某种程度上,该表达式在所有卸载/重新安装周期中都幸免了),XDebug立即重新开始正常工作。
糟糕的是,监视列表表达式会导致整个XDebug堆栈卷曲并死亡,但是确实如此。认为这种值得与他人分享的经验无疑会在将来遇到类似的问题,并最终在这里寻找答案。
答案 3 :(得分:0)
首先删除监视变量。这是VScode的错误。