Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging IDE's port connection to XDebug: "Waiting to Connect"

Preamble

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?


Setup

  • Ubuntu 10.10
  • Netbeans 6.9.1
  • PHP 5.3.3-1ubuntu9 with Suhosin-Patch
  • Xdebug v2.1.0 with debugclient built Sep 20 2010 from source using the tailored installation instructions script on xdebug.org
  • Apache Apache/2.2.16
  • Both /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini have:
    •  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" 

Procedure

The Problem

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

Debugging XDebug

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 

What is the correct way to debug the connection between the IDE and XDebug?

like image 645
Myer Avatar asked Oct 17 '10 20:10

Myer


People also ask

What is xdebug Remote_host?

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.

What is xdebug Client_host?

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.


1 Answers

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.

like image 131
reh Avatar answered Oct 11 '22 01:10

reh