Tra*_*pce 5 php xampp macos xdebug visual-studio-code
在 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);
?>
Run Code Online (Sandbox Code Playgroud)
我正在使用 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
Run Code Online (Sandbox Code Playgroud)
我使用自制程序安装了 Xdebug。
这是我的 php 信息:
phpinfo.htm
Xdebug 向导告诉我 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
}
]
}
Run Code Online (Sandbox Code Playgroud)
有人知道我做错了什么吗?
xdebug.remote_connect_back = 1在 ini 文件中设置
为 n00dl3 后,建议调试大部分时间都有效,但偶尔我会
在调试控制台中收到以下错误:
<- threadEvent
ThreadEvent {
seq: 0,
type: 'event',
event: 'thread',
body: { reason: 'exited', threadId: 1 } }
Run Code Online (Sandbox Code Playgroud)
我也遇到了这个问题,不是在相同的环境(NGINX服务器+ php-fpm)下,而是相同的症状。原来是我的xdebug配置造成的。
我如何诊断它:通过编写一个简单的 PHP 脚本进行测试,就像 OP 所做的那样:
<?php
xdebug_info();
Run Code Online (Sandbox Code Playgroud)
通过浏览它,我获得了有关我的设置的大量信息,包括:
xdebug.client_host => localhost
xdebug.client_port => 9003
Run Code Online (Sandbox Code Playgroud)
而我的 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
Run Code Online (Sandbox Code Playgroud)
然后在 VScode 中重新运行调试会话,添加一些断点,然后重新浏览脚本:弹出我的 VScode 窗口,执行在断点处暂停,并且可以像预期一样在调试面板中访问变量。
编辑:不要忘记:
xdebug.mode=debug到您的php.iniphp-fpm服务。似乎需要在 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
}
]
}
Run Code Online (Sandbox Code Playgroud)
现在断点可以正常工作了。
| 归档时间: |
|
| 查看次数: |
27322 次 |
| 最近记录: |