Like many, I've spent more hours debugging my IDE’s connection to XDebug than I have using XDebug to debug my programs. I’ve gotten it to work repeatedly, but every once and a while I get the common “Waiting to connect” problem. I haven’t been able to localize what causes XDebug to work or fail. I’ve been using ubuntu for two years; I’m neither a noob nor an strace guru. What am I doing wrong? How can I better debug my IDE’s connection to XDebug?
zend_extension = /usr/lib/php5/20090626+lfs/xdebug.so xdebug.remote_enable=1 xdebug.remote_handler=dbgp xdebug.remote_mode=req xdebug.remote_host=127.0.0.1 xdebug.remote_port=9000 xdebug.remote_log=/var/log/xdebug.log xdebug.extended_info=1 xdebug.idekey="netbeans-xdebug"
I can't explain what causes the problem or when the problem manifests. It begins when I try to debug my project, which causes my dev browser of choice (Chrome) to open to the url of my project with the parameter XDEBUG_SESSION_START=netbeans-xdebug
. This causes the page to render normally in chrome while Netbeans reports only “Waiting to Connect.”
First, with the “Waiting to Connect” message still alive, I’ll try to use netstat to dig around port 9000, which goes something like this:
$ netstat -an | grep 9000 tcp6 0 0 :::9000 :::* LISTEN
I shut down my IDE and try to use two files to help figure out what’s going on: {webroot}/index.php
contains <?php phpinfo(); ?>
, and {webroot}/dbgtest.php
contains the XDebug installation check script:
<?php $address = '127.0.0.1'; $port = 9000; $sock = socket_create(AF_INET, SOCK_STREAM, 0); socket_bind($sock, $address, $port) or die('Unable to bind'); socket_listen($sock); $client = socket_accept($sock); echo "connection established: $client"; socket_close($client); socket_close($sock); ?>
When I start the XDebug debugclient
and open http://127.0.0.1/dbgtest.php?XDEBUG_SESSION_START=mysession
, I’ll usually get the regular output and then verify XDebug is connected to the script with netstat in another terminal:
$ netstat -an | grep 9000 tcp 0 0 127.0.0.1:9000 127.0.0.1:34831 ESTABLISHED tcp 0 0 127.0.0.1:34831 127.0.0.1:9000 ESTABLISHED
Though both of these seem to indicate that the connection has been made, the webpage reads "Unable to bind", which I can't explain. I Ctrl-c to quit debugclient, and netstat at this point verifies that port 9000 has no activity. I fire up Netbeans, open {webroot}/index.php
and engage the debugger, which opens up http://127.0.0.1/index.php
. The debugger then usually starts normally. I stop the debugger, go back to my project, and this is where the problem really becomes annoying: some of the time, I can continue debugging my project as normal, and other times, the problem re-emerges and while the “Waiting to Connect” sign is displaying, netstat shows:
$ netstat -an | grep 9000 tcp6 0 0 :::9000 :::* LISTEN tcp6 0 0 127.0.0.1:9000 127.0.0.1:34681 TIME_WAIT
Other times, I'll restart my computer, fire up a terminal, and find:
$ netstat -an | grep 9000 unix 3 [ ] STREAM CONNECTED 9000 $ telnet 127.0.0.1 9000 Trying 127.0.0.1... telnet: Unable to connect to remote host: Connection refused
I'm not familiar enough with network and linux internals to see what this points to. Clearly something is using port 9000. What does this mean? Note that despite my settings in php.ini:
$ cat /var/log/xdebug.log cat: /var/log/xdebug.log: No such file or directory
Xdebug is an extension for PHP to assist with debugging and development. It was determined that Xdebug is configured with xdebug. remote_connect_back option enabled as shown in the following example. xdebug.remote_enable= true xdebug.remote_connect_back= true xdebug.remote_host= 127.0.
client_host = localhost # Configures the IP address or hostname where Xdebug will attempt to connect to when initiating a debugging connection. This address should be the address of the machine where your IDE or debugging client is listening for incoming debugging connections.
If you by chance use the Cisco VPN client, this could be a cause. It comes with a firewall, which is always on, even if the client is not started. It can be unchecked in the Options menu.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With