Xdebug:[单步调试] 连接调试客户端超时,等待:200 毫秒。尝试过:本地主机:9003

2024-02-19

我的 php.ini 配置:

[XDebug]
zend_extension = "C:\xampp\php\ext\php_xdebug.dll"   
xdebug.mode = debug 
xdebug.remote_autostart = on
xdebug.profiler_enable = on
xdebug.profiler_enable_trigger = on
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir ="c:/xampp/tmp"
xdebug.show_local_vars=0
xdebug.remote_host = 127.0.0.1
xdebug.remote_enable = 1
xdebug.remote_port = 9003
xdebug.remote_handler = dbgp
xdebug.remote_mode = req
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=1
xdebug.remote_autostart=1
xdebug.idekey=PHPSTORM
xdebug.remote_log="c:/xampp/tmp/xdebug.log"

我的 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": 9003
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9003
        }
        

    ]
}

但我仍然在 error.log 中收到此错误:

[php:notice] [pid 9388:tid 1840] [client ::1:63322] Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(, referer: http://localhost/online-store/admin/types/insert-types.php

首先我使用了端口 9000,但它不起作用,然后我尝试将 php.ini 和 launch.json 中的端口更改为 9003,与错误日志中的端口相同,但仍然没有任何反应,并且 XDebug 不工作并且不停止断点。


在将我的 Xdebug 库更新到 3+ 版本后,我也遇到了这样的错误。

我发现新的设置xdebug.start_with_request = yes配置 Xdebug 在每个请求上建立连接。

与此同时官方doc https://xdebug.org/docs/all_settings#start_with_request提供使用xdebug.start_with_request = trigger仅当明确指出需要时才连接 Xdebug。在这种情况下,我可以通过 GET 参数传递额外的密钥来启动步骤调试过程,例如http://localhost/?XDEBUG_TRIGGER=1,但这对我来说很不方便,我只想像往常一样在 VSCode 中按 F5 开始调试。

所以我的解决方案如下。我离开了start_with_request = yes并通过传递关闭大部分 Xdebug 通知xdebug.log_level = 0。然后我覆盖log_level within launch.json文件以启用所有警告,但仅限于调试会话内。

php.ini:

[XDebug]
zend_extension = php_xdebug-3.0.4-7.4-vc15-x86_64.dll
xdebug.mode = debug,develop
xdebug.discover_client_host = yes
xdebug.log_level = 0
xdebug.log = "%sprogdir%/userdata/temp/xdebug/log.txt"
xdebug.start_with_request = yes
xdebug.idekey = VSCODE

启动.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "env": {
                "XDEBUG_CONFIG": "log_level=7",
            }
        }
    ]
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Xdebug:[单步调试] 连接调试客户端超时,等待:200 毫秒。尝试过:本地主机:9003 的相关文章