skip to Main Content

I am trying to debug remote PHP scripts using xdebug. When xdebug is enabled for a website, if xdebug is able to make a tcp connection, the PHP script freezes as though waiting for a breakpoint to be executed. The JavaScript portion of the webpage is displayed correctly, just waiting on the PHP code to return data required to complete the page.

This has worked in the past. I can’t for the life of me figure out why.

If xdebug is unable to make establish a TCP session with the remote host, all works as expected.

I am using Angular 10 as my development environment and PhpStorm as my IDE.

Environment:

Debian bullseye (testing)
Apache2.4
PHP 7.4.11
mpm_prefork
xdebug.so 2.9.8

I have also tried xdebug.so v2.8.x and v3.0.0 (Beta) to no effect.

Current /etc/php/7.4/mods-available/xdebug.ini:

#set xdebug flags/values
zend_extension=xdebug.so    

xdebug.remote_autostart=0
xdebug.remote_enable=1
xdebug.remote_connect_back=0
xdebug.remote_host=MyClientIP    
xdebug.remote_port=9099
xdebug.idekey=PHPSTORM
    
#xdebug logger
xdebug.remote_log = /var/log/xdebug/xdebug.log

While I am using PhpStorm to develop my application, this issue it is not related to my IDE. To illustrate this I downloaded dbgbClient.exe from xdebug.org.

When using the script a session is created between the client and server.

Client output:

dbgpClient.exe  -p 9099 -f
Xdebug Simple DBGp client (0.4.1)
Copyright 2019-2020 by Derick Rethans

Waiting for debug server to connect on port 9099.
Connect from 10.130.189.1:39144
DBGp/1.0: Xdebug 2.9.8 — For PHP 7.4.11
Debugging file:///home/init/DEV/MT4/php-services/ClassAPI.php (ID: 70831/PHPSTORM)
1 | feature_get
1 | supports_async: supported > 0

xdebug.log from server:

[70831] Log opened at 2020-10-14 20:59:24
[70831] I: Connecting to configured address/port: myClientIP:9099.
[70830] Log opened at 2020-10-14 20:59:24
[70830] I: Connecting to configured address/port: MyClientIP:9099.
[70831] I: Connected to client. :-)
[70831] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///home/init/DEV/MT4/php-services/ClassAPI.php" language="PHP" xdebug:language_version="7.4.11" protocol_version="1.0" appid="70831" idekey="PHPSTORM"><engine version="2.9.8"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2020 by Derick Rethans]]></copyright></init>

[70830] I: Connected to client. :-)
[70830] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///home/init/DEV/MT4/php-services/ClassAPI.php" language="PHP" xdebug:language_version="7.4.11" protocol_version="1.0" appid="70830" idekey="PHPSTORM"><engine version="2.9.8"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2020 by Derick Rethans]]></copyright></init>

At this point the beginnings of the web page is created.

If I issue a run command and an extra carriage return or two, the debug session continues and the screen finishes.

Client example:

(cmd) run
2 | run > stopping/ok

(cmd)
Error while handling connection: Error reading length: EOF
Disconnect
Connect from 10.130.189.1:39146
DBGp/1.0: Xdebug 2.9.8 — For PHP 7.4.11
Debugging file:///home/init/DEV/MT4/php-services/ClassAPI.php (ID: 70830/PHPSTORM)
1 | feature_get
1 | supports_async: supported > 0

(cmd) run
2 | run > stopping/ok

(cmd)
Error while handling connection: Error reading length: EOF
Disconnect

xdebug log for the above:

[70831] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_get" transaction_id="1" feature_name="supports_async" supported="1"><![CDATA[0]]></response>

[70831] <- run -i 2
[70831] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="2" status="stopping" reason="ok"></response>

[70831] <- run -i 3
[70831] Log closed at 2020-10-14 21:00:32

[70830] <- feature_get -i 1 -n supports_async
[70830] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_get" transaction_id="1" feature_name="supports_async" supported="1"><![CDATA[0]]></response>

[70830] <- run -i 2
[70830] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="2" status="stopping" reason="ok"></response>

[70830] <- run -i 3
[70830] Log closed at 2020-10-14 21:00:41

[70829] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="4" status="stopping" reason="ok"></response>

[70829] Log closed at 2020-10-14 21:13:17

[70832] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="4" status="stopping" reason="ok"></response>

[70832] Log closed at 2020-10-14 21:13:38

Thank you for reading this far. I’m sure someone out there has a solution.

2

Answers


  1. Chosen as BEST ANSWER

    Well, it turns out there is something between my development PC connected to my companies network via VPN. I all worked at one time. Thanks to IT tightening the security screws (firewall rules).

    Although my PhpStorm would see the PHPSTORM cookie and establish a TCP session on the correct port, the protocol would not continue to completion. I'm guessing there is some type if smart firewall on the network.

    The secret was to establish a ssh tunnel between my PC and the linux server like so:

    ssh -R 9000:localhost:9000 username_goes_here@hostname_goes_here
    

    I also modified my /etc/php/7.4/mods-available/xdebug.ini as so: (The magic sauce is xdebug.remote_host=127.0.0.1

    zend_extension=xdebug.so    
    xdebug.remote_log=/var/log/xdebug/xdebug.log    
    xdebug.remote_host=127.0.0.1
    xdebug.remote_enable=1
    xdebug.idekey=PHPSTORM
    

    Thus the ssh tunnel will connect to port 9000 on the server with local port 9000 on the PC as the other end of the tunnel.

    Then all that had to be done is to setup PhpStorm. For that (and where these instructions originated) see here.

    Just a note - I only tested a php script access though a web browser. I have not tested a CLI based PHP script, but I'm guessing the answer is much the same.

    If you need more information on ssh port forwarding (tunneling) see here.


  2. This is the relevant part:

    Error while handling connection: Error reading length: EOF
    Disconnect

    xdebug is not meant to connect to remote (live) sites, to begin with.

    And even if stunnel is working, it might still fail to connect back for some reason …eg.

    xdebug.remote_host=EXTERNAL_ROUTER_IP
    xdebug.remote_connect_back=1
    

    And the port-forward :9099 to the internal MyClientIP in the router.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search