Home > Net >  How to Interpret XDEBUG Log File Entries
How to Interpret XDEBUG Log File Entries

Time:10-07

There comes a time when debugging that you hit a brick wall. All the logs indicate that my PHP.XDEBUG setup (client running VSCODE and Windows Server with PHP/XDEBUG) should be working but it is triggering a "Fatal error" in the log file that is not helping me to interrupt the problem - There appear to be extraneous breakpoints being identified but I have cleared everything, so the question is can anybody please help: In summary:

  1. XDEBUG has produced a log file
  2. It has connected to the client machine
  3. It has identified the localhost project path c:/Development-DEV/VSCode/Prog/phpinfo.php -n 3
  4. It has identified the breakpoint (line 3)

Here is the project and launch.json being debugged and deployed to the server:

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

Launch.json file

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

Here is the PHP.INI file [XDEBUG} settings from the Windows Server:

[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'

Here is the XDEBUG log taken from the server.

    [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

CodePudding user response:

The log file has the following lines:

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

VS Code and its plugin set this breakpoint:

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

The paths in these don't match, which usually hints that you need to set-up path mappings. Xdebug can only see the file location on the system where PHP *runs, whereas the IDE (VS Code) uses the path it sees on the file system where your development files are.

I do not know how you synchronise these yourself though.

You can make path mappings in your launch.json file, as follows:

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

I have made a YouTube video which explains this in more detail as well, starting at 3:48: https://youtu.be/ZIGdBSD6zvU?t=229.


You probably also want to remove these settings:

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

CodePudding user response:

Xdebug 2 uses port 9000 Xdebug 3 uses port 9003 https://xdebug.org/docs/upgrade_guide

  • Related