在Visual Studio Code(1.9.1)(mac)中,我已经设置了 php-debug 插件。
在调试屏幕中,我开始' 收听Xdebug '。
在此之后,我在我的XAMPP服务器(本地)上打开index.php
但没有任何反应。
我尝试在以下代码中使用断点:
<?php
$i = 0;
do {
$i++;
if (!($i % 1)) {
echo('<p>$i = ' . $i . '</p>');
}
}
while ($i < 100);
?>
我正在使用XAMPP,在我的 php.ini 文件中,我使用端口9000作为Xdebug。
zend_extension="/usr/local/Cellar/php71-xdebug/2.5.0/xdebug.so"
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote.port=9000
我使用自制软件安装了Xdebug
这是我的PHP信息:
phpinfo.htm
Xdebug wizard告诉我Xdebug已正确安装。
我的 launch.json 文件如下所示:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"log": true
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
有人知道我做错了吗?
在ini文件中设置xdebug.remote_connect_back = 1
后
因为n00dl3建议大部分时间调试工作,但偶尔我得到以下
调试控制台中出错:
<- threadEvent
ThreadEvent {
seq: 0,
type: 'event',
event: 'thread',
body: { reason: 'exited', threadId: 1 } }
答案 0 :(得分:1)
似乎需要设置服务器根目录 在launch.json中使用 localSourceRoot ,如下所示:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"log": true,
"localSourceRoot": "http://127.0.0.1/public_html/"
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
现在断点工作正常。
答案 1 :(得分:1)
我也遇到了这个问题,不是在相同的环境(NGINX服务器+ php-fpm
)下,而是在相同的症状下。原来是我的xdebug
配置引起的。
我如何诊断它:就像编写OP一样,编写一个简单的PHP脚本进行测试:
<?php
xdebug_info();
通过浏览它,我在设置中获得了很多信息,包括:
xdebug.client_host => localhost
xdebug.client_port => 9003
而我的xdebug在端口9900上侦听(默认为9000)。
修复步骤:只需将以下几行添加到您的php.ini
或xdebug.ini
中(无论xdebug配置的其余部分位于何处):
# This should match your xdebug.remote_host
xdebug.client_host=localhost
# This should match your xdebug.remote_port
xdebug.client_port=9900
xdebug.mode=debug
然后在VScode中重新运行调试会话,添加一些断点,然后重新浏览到脚本:我的VScode窗口弹出,在断点处暂停执行,并且可以按预期在调试面板中访问变量。< / p>
编辑:也不要忘记:
xdebug.mode=debug
添加到您的php.ini
php-fpm
服务。答案 2 :(得分:0)
这是我的launch.json,调试不起作用
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"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
}
]
}
这是在我的php.in中
[xdebug] zend_extension =
"c:/wamp64/bin/php/php7.4.0/zend_ext/php_xdebug-2.8.0-7.4-vc15-x86_64.dll"
xdebug.remote_enable = on
xdebug.remote_autostart = on
答案 3 :(得分:0)
检查 xdebug.client_port 在页面 xdebug_info();或 phpinfo();
在 vscode 的 launch.json 中配置相同的端口
答案 4 :(得分:0)
我也遇到了这个问题。
不知何故,有一天,不知不觉中,我安装了 xdebug 的第 3 版,并且更改了很多 conf 参数名称,参见 this SO question
因此,例如使用 phpinfo 验证 xdebug 版本值得一试。