在调试时,有时会碰壁.所有日志(log)都表明我的PHP.XDEBUG设置(运行VSCODE和带有PHP/XDEBUG的Windows服务器的客户端)应该正常工作,但它在日志(log)文件中触发了一个"致命错误",这无助于我中断问题-似乎识别了无关的断点,但我已经清除了所有内容,所以问题是有人能帮助我吗?总结如下:

  1. XDEBUG已生成日志(log)文件
  2. 它已连接到客户端计算机
  3. 它已经标识了本地主机项目路径c:/Development-DEV/VSCode/Prog/phpinfo.php -n 3
  4. 它已经标识了断点(第3行)

以下是正在调试并部署到服务器的项目和Launch.json:

 1 <?php
 2
 3 echo "Hello"; <- breakpoint
 4 echo "world"; 
 5
 6 ?>

Launch.json文件

 {
   "name": "Listen for XDebug",
   "type": "php",
   "request": "launch",
   "port": 9003,
   "log": true, 
    }

以下是Windows服务器中的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日志(log).

    [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

推荐答案

日志(log)文件包含以下行:

<init … fileuri="file:///C:/inetpub/wwwroot/phpinfo.php" …

VS代码及其插件设置了此断点:

breakpoint_set -i 3 -t line -f file:///c:/Development-DEV/VSCode/Prog/phpinfo.php

其中的路径不匹配,这通常提示您需要设置路径映射.XDEBUG只能看到运行PHP*的系统上的文件位置,而IDE(VS代码)使用它在开发文件所在的文件系统上看到的路径.

不过,我不知道您自己是如何同步这些内容的.

您可以在launch.json文件中进行路径映射,如下所示:

{
    "name": "Listen for XDebug",
    "type": "php",
    "request": "launch",
    "port": 9003,
    "log": true, 
    "pathMappings": [
         "file:///C:/inetpub/wwwroot" : "file:///c:/Development-DEV/VSCode/Prog"
    ]
}

我制作了一段YouTube视频,从3:48:https://youtu.be/ZIGdBSD6zvU?t=229开始,更详细地解释了这一点.


您可能还想删除这些设置:

xdebug.remote_enable = 1       // old Xdebug 2 setting
xdebug.remote_autostart = 1    // old Xdebug 2 setting
xdebug.remote_handler=dbgp     // old Xdebug 2 setting
xdebug.remote_connect_back = 0 // old Xdebug 2 setting

xdebug.discover_client_host=true // your log indicates that this fails, and that it falls back

Php相关问答推荐

在WooCommerce中执行一次银行电汇确认付款代码

有条件的运费率基于购物车小计与WooPayments货币转换

使用箭头函数语法时,在回调范围内无法访问变量变量(警告:未定义的变量)

WooCommerce短代码,显示特定产品的购物车徽章中的当前数量

如何将WooCommerce产品从一个产品复制到另一个产品S

在WooCommerce中只允许高价产品的BACS付款

ANTLR4-lexer如何消耗更多的 token 并停止现有规则?

除WooCommerce中的特定国家/地区外,有条件地要求填写邮政编码 checkout 字段

既然setSQLLogger()已被弃用,如何使用中间件在 Doctrine 3 中记录查询执行时间?

显示自定义 Laravel 9 公共属性的错误

显示 woocommerce 中所选变体的属性术语描述

API 平台 - UI 服务器端点定义

为什么 php 只能在我的 Nginx Web 服务器的某些目录中工作?

尽管有use指令,PHP 类在其他文件中仍处于可见状态

如何搜索和替换 XML 文件中的一段文本?

PHP文件如何从CSS执行

为 WordPress 页面创建新功能

如何从此字符串创建 Carbon 对象:2022-06-21T05:52:46.648533678Z?

使用 PHP 正则表达式从仅包含具有现有顺序的顶级标签的 XML 文档中搜索和创建数组

如何将文件直接上传到 Cloudinary 而不先保存在 public 文件夹中