如何解读XDEBUG日志条目?VSCode+Windows Server调试异常求助
PHP+Xdebug调试断点异常问题排查
问题概述
- Xdebug已生成日志,且成功连接到VSCode客户端
- 日志显示识别到本地项目路径
c:/Development-DEV/VSCode/Prog/phpinfo.php第3行的断点,但实际已清除所有手动断点 - 日志中出现的"Fatal error"相关断点无法帮助定位问题
相关配置与代码
待调试代码
<?php echo "Hello"; // <- 原断点位置 echo "world"; ?>
VSCode的launch.json配置
{ "name": "Listen for XDebug", "type": "php", "request": "launch", "port": 9003, "log": true }
Windows Server的php.ini中Xdebug配置
[XDebug] ;zend_extension = "C:\php\ext\php_xdebug-2.7.0RC1-7.3-vc15-nts-x86_64.dll" zend_extension = "C:\php-7.4.30-nts-Win32-vc15-x64\ext\php_xdebug-3.1.5-7.4-vc15-nts-x86_64.dll" ;zend_extension = "php_xdebug.dll" xdebug.remote_enable = 1 xdebug.remote_autostart = 1 xdebug.client_port=9003 xdebug.remote_handler=dbgp xdebug.remote_connect_back = 0 xdebug.mode = debug xdebug.start_with_request = yes xdebug.client_host=localhost xdebug.discover_client_host=true xdebug.idekey=VSCODE xdebug.output_dir="C:\InetPub\wwwroot\logs\" xdebug.log = 'C:\InetPub\wwwroot\logs\xdebug.log'
Xdebug日志内容
[3516] Log opened at 2022-10-07 06:47:58.635802 [3516] [Step Debug] INFO: Checking remote connect back address. [3516] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'. [3516] [Step Debug] INFO: Checking header 'REMOTE_ADDR'. [3516] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 121.152.74.44:9003. [3516] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured address/port: localhost:9003. :-| [3516] [Step Debug] INFO: Connected to debugging client: 121.152.74.44:9003 (from REMOTE_ADDR HTTP header), localhost:9003 (fallback through xdebug.client_host/xdebug.client_port). :-) [3516] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///C:/inetpub/wwwroot/phpinfo.php" language="PHP" xdebug:language_version="7.4.30" protocol_version="1.0" appid="3516" idekey="VSCODE"><engine version="3.1.5"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2022 by Derick Rethans]]></copyright></init> [3516] [Step Debug] <- feature_set -i 1 -n max_children -v 100 [3516] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="max_children" success="1"></response> [3516] [Step Debug] <- feature_set -i 2 -n max_data -v 8192 [3516] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="max_data" success="1"></response> [3516] [Step Debug] <- breakpoint_set -i 3 -t line -f file:///c:/Development-DEV/VSCode/Prog/phpinfo.php -n 3 [3516] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="3" id="35160009"></response> [3516] [Step Debug] <- breakpoint_set -i 4 -t exception -x "Fatal error" [3516] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="4" id="35160010"></response> [3516] [Step Debug] <- breakpoint_set -i 5 -t exception -x "Parse error" [3516] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="5" id="35160011"></response> [3516] [Step Debug] <- breakpoint_set -i 6 -t exception -x "Unknown error" [3516] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="6" id="35160012"></response> [3516] [Step Debug] <- run -i 7 [3516] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="7" status="stopping" reason="ok"></response> [3516] Log closed at 2022-10-07 06:48:00.608238
日志解读与问题解决
日志关键信息解读
- 连接状态:Xdebug先尝试通过HTTP头的
REMOTE_ADDR连接客户端121.152.74.44:9003失败, fallback到配置的localhost:9003后成功连接,网络连接无问题。 - 断点来源:所有
breakpoint_set指令均为VSCode客户端主动发送:- 第3条指令是设置本地
c:/Development-DEV/VSCode/Prog/phpinfo.php第3行的断点,大概率是VSCode缓存的旧断点配置 - 第4-6条是设置
Fatal error/Parse error/Unknown error的异常断点,属于VSCode PHP调试插件的默认初始化行为,并非异常。
- 第3条指令是设置本地
- 执行结果:
run指令后返回status="stopping",说明脚本正常执行完毕,未触发任何断点(包括异常断点),代码本身无错误。
核心问题定位
- 路径映射缺失:服务端实际运行文件为
C:/inetpub/wwwroot/phpinfo.php,但VSCode发送的断点路径是本地的c:/Development-DEV/VSCode/Prog/phpinfo.php,Xdebug无法关联两个路径,导致断点无法命中。 - “多余断点”误解:日志中的异常断点是插件默认配置,并非手动设置的冗余断点。
解决步骤
- 添加路径映射到launch.json:在配置中加入
pathMappings,关联服务端与本地路径:
注:{ "name": "Listen for XDebug", "type": "php", "request": "launch", "port": 9003, "log": true, "pathMappings": { "C:/inetpub/wwwroot": "${workspaceFolder}" } }${workspaceFolder}对应VSCode当前打开的项目根目录,需确保本地项目根目录与服务端C:/inetpub/wwwroot对应。 - 清理VSCode缓存断点:
- 关闭VSCode,删除项目目录下
.vscode文件夹(备份launch.json后操作) - 重启VSCode,重新配置调试环境,如需断点则重新设置
- 关闭VSCode,删除项目目录下
- 优化Xdebug 3配置:删除Xdebug 2的冗余参数,简化配置:
[XDebug] zend_extension = "C:\php-7.4.30-nts-Win32-vc15-x64\ext\php_xdebug-3.1.5-7.4-vc15-nts-x86_64.dll" xdebug.mode = debug xdebug.start_with_request = yes xdebug.client_port=9003 xdebug.client_host=121.152.74.44 # 直接指定客户端IP,避免连接fallback xdebug.idekey=VSCODE xdebug.log = "C:\InetPub\wwwroot\logs\xdebug.log"
内容的提问来源于stack exchange,提问作者user6743474
相关产品推荐
相关产品推荐

