我正在尝试让XDebug在Windows 10上与Visual Studio Code一起使用。我在本地计算机上运行Apache / PHP服务器(Apache / 2.4.41(Win64)PHP / 7.3.9RC1)。它可以正常工作。我在同一台计算机上运行Visual Studio Code。我已经在其中安装了PHP XDebug 1.13。我在htdocs目录中有一个小的测试脚本。我设置了两个断点,然后启动调试器,然后在调试控制台中获取它...
<- launchResponse
Response {
seq: 0,
type: 'response',
request_seq: 2,
command: 'launch',
success: true }
然后,我切换到Chrome,该Chrome当时有一个箭头沙漏,所以我可以说某些事情正在起作用。我刷新页面,调试器不会在断点处停止。
我已经阅读了很多帖子。这是我的php.ini文件中的相关条目...
[XDebug]
xdebug.stopOnEntry = true
xdebug.remote_host = "127.0.0.1"
xdebug.remote_port=9001
xdebug.remote_connect_back=1
xdebug.remote_enable = 1
xdebug.remote_autorestart = 1
zend_extension = "d:/php/ext/php_xdebug-2.7.2-7.3-vc15-x86_64.dll"
这是我当前的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": 9001,
"hostname": "127.0.0.1",
"log": true,
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9001,
}
]
}
我尝试过:
这是我的测试脚本...
<?php
$a = 3;
$b = 19;
$c = $a + $b;
echo "Answer: $c";
?>
我显然希望调试器在第一个断点处停止(它在“ $ a = 3 ;;”上没有。我尝试添加更多的断点。浏览器直接进入答案“答案:22“
另一件事,我尝试输入echo "1"
在调试控制台底部的提示中,得到以下信息:
echo "1"
Cannot evaluate code without a connection
-> evaluateRequest
{ command: 'evaluate',
arguments: { expression: 'echo "1"', context: 'repl' },
type: 'request',
seq: 3 }
因此,我猜测Web服务器未连接。我已经检查了error.log文件,但是没有错误...没有任何迹象表明与调试或连接有关。
注意:我打开了防火墙上的入站和出站端口,并运行了[[netstat -ano,并验证了正在监听端口9001 ...
TCP 127.0.0.1:9001 0.0.0.0:0 LISTENING 16144
任何帮助将不胜感激!
{
// 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,
"stopOnEntry": true, // Once working, comment out this line
"pathMappings": {
// eg your web files in C:\Path\To\Code
"/mnt/c/Path/To/Code": "${workspaceFolder}"
},
"log": true
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
和我的xdebug.ini是:
zend_extension=xdebug.so xdebug.remote_enable=1 xdebug.remote_autostart = 1