使用Xdebug DBGp proxy+PhpStorm远程调试时遇[507]命令错误求助
解决Xdebug DBGp proxy配合PhpStorm远程调试时的[507]命令识别错误
环境信息
- Ubuntu 22.10
- PHP 8.1
- Xdebug v3.1.2
- Xdebug DBGp proxy (0.4.2-dev)
DBGp proxy启动日志
./dbgpProxy Xdebug DBGp proxy (0.4.2-dev) Copyright 2020 by Derick Rethans 2023-02-13 07:16:48.394 [warn] [SSL] The 'certs/fullchain.pem' file could not be found, not enabling SSL listeners 2023-02-13 07:16:48.394 [info] [dbgpProxy] Proxy started 2023-02-13 07:16:48.395 [info] [server] Started server server on 127.0.0.1:9003 2023-02-13 07:16:48.395 [info] [server] Started client server on 127.0.0.1:9001
Xdebug配置
zend_extension=xdebug.so xdebug.mode=debug xdebug.client_host=127.0.0.1 xdebug.client_port=9003 xdebug.log=/tmp/xdebug.log
SSH转发配置
RemoteForward 9001 localhost:9001 LocalForward 9001 localhost:9001
IDE注册操作及日志
执行工具 -> DBGp proxy -> 注册IDE后,日志如下:
2023-02-13 07:17:08.768 [info] [server] Start new client connection from 127.0.0.1:33682 2023-02-13 07:17:08.839 [info] [proxyinit] [POLYANIN] Added connection for IDE Key 'POLYANIN': 127.0.0.1:9001 2023-02-13 07:17:08.840 [info] [server] Closing client connection from 127.0.0.1:33682
错误现象
设置断点并刷新页面后,出现如下错误日志:
2023-02-13 07:28:18.141 [info] [proxy-client] [POLYANIN] Found connection for IDE Key 'POLYANIN': 127.0.0.1:9001 2023-02-13 07:28:18.141 [info] [proxy-client] [POLYANIN] Connecting to 127.0.0.1:9001 2023-02-13 07:28:18.142 [info] [proxy-client] [POLYANIN] IDE connected 2023-02-13 07:28:18.142 [info] [server] Start new client connection from 127.0.0.1:33694 2023-02-13 07:28:18.142 [info] [proxy-client] [POLYANIN] Init forwarded, start pipe 2023-02-13 07:28:18.142 [warn] [server] Handler response error: Error reading command: Don't understand command '[507]' 2023-02-13 07:28:18.142 [info] [server] Closing client connection from 127.0.0.1:33694 2023-02-13 07:28:18.192 [info] [proxy-client] [POLYANIN] IDE closed connection
解决步骤
1. 排查端口占用冲突
[507]是HTTP状态码,说明DBGp proxy接收到了HTTP请求而非DBGp协议指令,大概率是端口被HTTP服务占用。执行以下命令检查9001端口的占用情况:
ss -tulpn | grep 9001
如果发现9001端口被Nginx/Apache等HTTP服务占用,需为DBGp proxy更换客户端端口,比如改为9002:
./dbgpProxy -c 0.0.0.0:9002
同时更新PhpStorm注册IDE时的端口为9002,以及SSH转发配置中的端口。
2. 修正SSH转发配置
不需要同时设置RemoteForward和LocalForward,根据调试场景调整:
- 若用本地PhpStorm调试远程服务器的PHP代码,仅保留
RemoteForward:
这里的RemoteForward 9002 本地IP:9002本地IP是PhpStorm所在机器的局域网IP或公网IP,确保远程服务器能访问到。
3. 补全Xdebug配置
确保Xdebug的IDE Key与PhpStorm注册的一致,在php.ini中添加:
xdebug.idekey=POLYANIN
重启PHP服务使配置生效。
4. 检查Xdebug日志
查看/tmp/xdebug.log内容,确认Xdebug发送的调试请求是否符合DBGp协议格式,排除Xdebug本身的配置问题。
内容的提问来源于stack exchange,提问作者Polyanin
相关产品推荐
相关产品推荐

