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

问题描述 投票:0回答:4

我的 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 不工作且不停止在断点上。

php apache visual-studio-code xampp xdebug
4个回答
25
投票

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

我发现新设置

xdebug.start_with_request = yes
配置Xdebug在每个请求上建立连接。

同时,官方 doc 提供使用

xdebug.start_with_request = trigger
以便仅在明确指出需要时连接 Xdebug。在这种情况下,我可以通过 GET 参数传递一个额外的键来启动单步调试过程,例如
http://localhost/?XDEBUG_TRIGGER=1
,但这对我来说很不方便,我只想在 VSCode 中按 F5 开始调试,就像我一直做的那样。

所以我的解决方案如下。我离开了

start_with_request = yes
并通过传递
xdebug.log_level = 0
关闭了大部分 Xdebug 通知。然后我在
log_level
文件中覆盖
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

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "env": {
                "XDEBUG_CONFIG": "log_level=7",
            }
        }
    ]
}

1
投票

我在 PHP8 中遇到了同样的问题。就我而言,这只是他们自己的向导建议的 XDebug 版本。 我使用这个版本,效果很好。 3.0.0-8.0-vs16


1
投票

launch.json:

       {
            "name": "Listen for Xdebug",  
            "type": "php",  
            "request": "launch",  
            "port": 9003,  
            "hostname": "localhost",  
            "pathMappings": {
                "/var/www/html": "${workspaceRoot}/www/"
            },
        },

根据您的要求更改路径映射,最重要的是主机名。添加后,它起作用了


0
投票

我的计算机开始使用不同的 IP 地址后收到此错误消息。发生这种变化的原因是,当我断开它与以太网电缆的连接后,它连接到了wifi路由器,这意味着一个新的IP地址。

解决方案是更改

/etc/php/8.1/apache2/php.ini
文件。我将行
xdebug.client_host=192.168.1.110
修改为
xdebug.client_host=192.168.1.107
,其中新值来自
ipconfig
命令的输出。

© www.soinside.com 2019 - 2024. All rights reserved.