PhpStorm receives incoming xdebug connections, but does nothing on them - php

I am running PhpStorm on one machine and I am running php-fpm on another. I have a ssh tunnel between them.
I have a proofs of the following statements:
ssh tunnel is configured correctly and works (I am using nc and nc -l to test it).
xdebug is configured correctly and works (I am using nc -l to receive it's connections and also I can use another IDE (vscode) successfully)
phpstorm is receiving incoming connections
My site has constantly refreshing page and on my tunnel console I see constant messages
connect_to localhost port 9001: failed
Which proves, that xdebug is trying to connect to IDE on each refresh but failing.
Then I am pressing
Start listening for PHP Debug Connections button and these messages disappear.
This means that ssh was now able to connect to IDE.
But the problem is nothing else happens. No any breakpoint triggers, no any dialog appears to provide mappings, nothing.
What else can be checked to fix this?
Php version is: 5.6.33-0+deb8u1
Xdebug version is: 2.2.5
Phpstorm version is: 2020.3
The following appears in xdebug log:
Log opened at 2020-12-22 12:14:17
I: Connecting to configured address/port: 127.0.0.1:9001.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///settings/html/load_menu.php" language="PHP" protocol_version="1.0" appid="13307" idekey="1"><engine version="2.2.5"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2014 by Derick Rethans]]></copyright></init>
<!**************** MY REMARK ********************!>
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>
Log closed at 2020-12-22 12:14:17
Note my remark place. If I receive connections with nc -l 9001 it waits in this place until I drop connection with Ctrl-C.
If I receive connection with PhpStorm or if I don't receive it, it passes this place immediately.
This means that phpstorm receives incoming connection and the drops it immediately. Why?
If I receive connections with vscode, a lot of messages like
<- breakpoint_list -i 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="1"></response>
appears in my remark place

No mistakes were found in setup. Turns out is was a bug in PhpStorm 2020.3 and switching to Preview build helped instantly. Thanks to #LazyOne :)

Related

NetBeans Xdebug Remote Host waiting for connection for infinite time

I am trying to configure Xdebug to my NetBeans IDE which is showing as "Waiting for Connection". I have already spent two days but I didn't find a clue on it.
I am connecting to the code which is in the remote server from my NetBeans IDE using SFTP Connection which is successful.
My Remote Server is a VM with the Cent OS 7.
My Application is configured with nginx, PHP-FPM, PHP 5.6.
I have installed xdebug-2.5.5 in the server and added the following in the php.ini:
zend_extension=/apps/php-fpm/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
xdebug.remote_autostart=0
xdebug.remote_enable=1
xdebug.remote_handler="dbgp"
xdebug.remote_mode="req"
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.idekey="netbeans-xdebug"
;xdebug.remote_connect_back=1
xdebug.profiler_enable_trigger=0
xdebug.remote_log="/mypath/xdebug.log"
I have cross checked that xdebug.so is located in the correct path which I mentioned above.
In my NetBeans, Tools >> Options >> PHP >> Debugging:
Debugging port: 9000
Session ID: netbeans-xdebug
When I start the Debugging in NetBeans IDE, I am seeing the below logs:
Log opened at 2021-11-24 07:11:45
I: Connecting to configured address/port: localhost:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///myserver/location/path/index.php" language="PHP" xdebug:language_version="5.6.14" protocol_version="1.0" appid="4643" idekey="netbeans-xdebug"><engine version="2.5.5"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2017 by Derick Rethans]]></copyright></init>
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="break" reason="ok"><xdebug:message filename="file:///myserver/location/path/index.php" lineno="13"></xdebug:message></response>
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>
Log closed at 2021-11-24 07:11:45
and in NetBeans IDE, "Waiting for Connection" is keep on loading for infinite time.
I am looking for some help to understand what is the problem on this. I am not using any Docker and PhpStorm. Looking forward for some help.
You say "My Remote Server is a VM with the Cent OS 7" but then you have xdebug.remote_host=localhost
Xdebug is the one that connects to the IDE and NOT other way around. If your code is run on another server (another physical machine or inside the VM or some container) then xdebug.remote_host should point to the machine where your IDE is running (an IP address or domain name that can be resolved to that IP; as seen from that server). Unless, of course, you are using reverse SSH tunnel for Xdebug connections.
Right now you are connecting to some service on your server on TCP 9000 port. Extremely likely that it will be php-fpm (that also uses that port: that's one of the reasons why Xdebug v3 have changed the default port to be 9003 BTW). Your Xdebug log is a very short one: a typical response of a service that knows how Xdebug works that just closes the session. php-fpm can do just that.
So a few suggestions:
To ensure that only Xdebug is using this port: change Xdebug port to another number (e.g. 9001 or maybe better 9003 so it will be compatible with Xdebug v3) in both php.ini as well as NetBeans. Do not forget to restart your web server/php-fpm after that (check live settings using phpinfo();).
If no reverse SSH tunnel is used then set xdebug.remote_host to have an IP of the machine with your NetBeans. Quite often that would be the same IP as seen in $_SERVER['REMOTE_HOST'].
NOTE: Since this will be an incoming connection the firewall on your local OS, on your server and your router (if it's outside of your LAN) can prevent such connection. So you would need to ensure that you can receive incoming connections on Xdebug port on your local machine.

Remote debugging with Xdebug causes PHP script execution to halt

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.
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.
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.

How to debug a remote PHP script that is called by a third server

I need to debug a PHP script on a remote server that I can not call from my web browser. Instead it is called by a third party server as a web hook.
Preferably I would like to make the webhook start a remote Xdebug session and step through the code in the NetBeans IDE that I am using.
I am using an SSH tunnel to connect the remote debugger to my development machine.
I can not use the GET/POST/COOKIE variable with the webhook so I have set xdebug.remote_autostart=1 to make the debug session start nontheless.
I have added a couple of break points to my page and have it opened in the IDE Editor while I fire up the webhook call from the third server.
Still a debug session is not started. I know that the page is executed because I have added some logging commands to it.
Is it at all possible to do what I want? Thanks for any hints and comments!
When answering please note: I will not accept any answer that recommends logging to a file because that is what I am already doing.
Thanks!
Here is the Xdebug section of my php.ini (and yes it is the correct php.ini file instance):
xdebug.idekey="netbeans-xdebug"
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_connect_back=0
xdebug.remote_autostart=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
Here is the Xdebug log of the session.
[21318] Log opened at 2019-04-01 19:50:38
[21318] I: Connecting to configured address/port: 127.0.0.1:9000.
[21318] I: Connected to client. :-)
[21318] -> <init xmlns="urn:debugger_protocol_v1"
xmlns:xdebug="https://xdebug.org/dbgp/xdebug"
fileuri="file:///var/www/couchback/update.php"
language="PHP"
xdebug:language_version="7.0.33-0ubuntu0.16.04.2"
protocol_version="1.0"
appid="21318"
idekey="netbeans-xdebug">
<engine version="2.7.0"><![CDATA[Xdebug]]></engine>
<author><![CDATA[Derick Rethans]]></author>
<url><![CDATA[https://xdebug.org]]></url>
<copyright><![CDATA[Copyright (c) 2002-2019 by Derick Rethans]]></copyright>
</init>
[21318]
[21318] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" status="stopping" re
ason="ok"></response>
[21318]
[21318] Log closed at 2019-04-01 19:50:40
The debug session is started but for some reason the IDE does not seem to take care. Probably that is because of the missing idekey in the uri? I have no means to add the idekey since the webhook originates from a third party. It might be an option to send the webhook to a proxy and forward the call with the idekey added to it. I will be happy to hear any other suggestions that are not as complicated.

Unable to debug using PhpStorm with EC2

I am trying to configure PhpStorm on my local machine and repository is on Amazon EC2. I used SSH tunnelling also but unable to debug using remote debugger.
Here are my configuration files I have placed same configuration in
/etc/php-5.6.d/xdebug.ini
/etc/php.ini
zend_extension=/usr/lib64/php/5.6/modules/xdebug.so
xdebug.remote_enable=1 ; Enable xdebug
xdebug.remote_autostart=Off ; Only start xdebug on demand, not on every request
xdebug.remote_host=127.0.0.1 ; This is unused if the next setting is 'On'
;xdebug.remote_connect_back=On ; Use a special $_SERVER['...'] variable to get the remote address
xdebug.remote_port=9002 ; Port on the IDE to connect back to. Usually it is 9000
xdebug.idekey="phpstorm" ; The IDE key which should match the XDEBUG_SESSION cookie valu
xdebug.remote_connect_back=1
xdebug.remote_log="/tmp/xdebug_remote_log.log"
xdebug.extended_info=1e
I'm creating SSH tunnel using the command given below
ssh -R 9002:localhost:9002 root#18.2xx.2xx.1xx
After turning off remote_connect_back the new logs are here
Log opened at 2018-04-23 15:59:32
I: Connecting to configured address/port: 127.0.0.1:9002.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/immunedata-prod/immunedata/website-php/index.php" language="PHP" xdebug:language_version="5.6.32" protocol_version="1.0" appid="15683" idekey="PHPSTORM"><engine version="2.5.5"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2017 by Derick Rethans]]></copyright></init>
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>
Log closed at 2018-04-23 15:59:32
How to resolve this issue, I'm not using port 9000 because there's another microservice running at that port.

PHPStorm not reacting to break points

I have recently installed PHPStorm and Xdebug in order to debug PHP scripts running on a local server. I am running Mac OS 10.8.5 and MAMP. I have been using Safari 6.2.4 as my principal browser, but the issue occurs also with Initially, I was able to get PHPStorm to stop at checkpoints I have placed, but in one script, it refused to enter a foreach() {} statement. I therefore created a small test script which contained only this statement, and tested it on its own. First PHPStorm was happy to step through each line, and then it refused to stop at any breakpoints at all, either in my small test script or in any other script.
I have spent several hours checking and rechecking the various official guides, and testing all the techniques suggested. At times, my test page will start to load, and then the progress bar in the browser will stop. I am guessing that PHPStorm is, in fact, reacting to the break point, but failing to show the debugger controls.
Here is a screenshot of this situation. Should there be another panel in the PHPStorm window, to allow me to step through the script? If so, how can I get it to appear? If not, is there any way of debugging the PHPStorm debugger?
Here are the xdebug settings in php.ini:
[xdebug]
zend_extension="/Applications/MAMP/bin/php/php5.5.3/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host="localhost"
xdebug.remote_port="9000"
xdebug.profiler_enable=1
xdebug.profiler_output_dir="/Applications/MAMP/tmp"
xdebug.remote_log="/Applications/MAMP/logs/xdebug.log"
I have a Run/Debug configuration set up in PHPStorm as:
Host: web Port: 9000
Document Root: /Volumes/Sites/web
Here's the output of the xdebug.log:
Log opened at 2015-05-20 12:06:48
I: Connecting to configured address/port: localhost:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///Volumes/Sites/web/test.php" language="PHP" protocol_version="1.0" appid="3174" idekey="1"><engine version="2.2.3"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2013 by Derick Rethans]]></copyright></init>
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>
Log closed at 2015-05-20 12:06:48
In the Run panel, I see:
/Applications/MAMP/bin/php/php5.5.3/bin/php -S jce:9000 -t /Volumes/Sites/web
[Wed May 20 08:06:48 2015] 127.0.0.1:51388 Invalid request (Malformed HTTP request)
The port number after 127.0.0.1: changes each time I refresh the browser.
PHPStorm also fails to react to breakpoints set in JavaScript files running in the browser.

Categories