29

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?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Myer
  • 3,670
  • 2
  • 39
  • 51
  • 1
    Sidenote, although your troubles seem to not fully apply here: I've been using fake vhosts (added to hosts file to resolve to 127.0.0.1) and debug on apache vhosts of the same ServerName/Alias, and it works like a charm with Xdebug. A setting to make sure you have set properlty is Project Properties --> Sources --> Web Root, and Sources --> Project URL/Index File so that your browser's /index.php corresponds to the one Xdebug expects in. – Fanis Hatzidakis Oct 18 '10 at 06:50
  • 1
    I had a smilar issue and it was the blindingly obvious: xdebug not installed. NetBeans silently assumes that xdebug is present, it never checks. So if some other NetBeans novice is having this issue, check that first :) – Móż Aug 29 '13 at 05:24

3 Answers3

5

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.

reh
  • 51
  • 1
  • 2
4

Please read this thread.

http://forums.netbeans.org/post-99369.html

in the end the workaround was to add net.ipv6.bindv6only = 0 to the file /etc/sysctl.d/bindv6only.conf and then reboot. Xdebug worked fine after that.

richrosa
  • 823
  • 6
  • 5
  • Interesting - I'll have to check this out when I investigate XDebug again; I'll mark the answer correct when I've done that (since I posted this I haven't used XDebug). – Myer Mar 28 '12 at 12:40
  • Wow, I've been working for hours and this fixed my issue, thanks! – Samer Bechara Aug 24 '14 at 08:23
2

Well, my development-set up somewhat differs from yours but I very well know this problem. In fact I just solved it ... this time my Fireeall blocked the port XDebug uses to talk to my IDE.

Some things come to my mind when reading your account:

1) "I can't explain what causes the problem or when the problem manifests." This is a very important statement b/c, as we all know, technichal solutions are strictly dependant on wheather the underlying problem occurs always or sometimes, in a seemingly random fashion. So ... can you sometimes perform XDebugging this way or never?

2) When your IDE is waiting and your browser renders the site immediately, then I guess there is something wrong with your IDE telling your XDebug-server to start. B/c if XDebug would start and couldn't connect back to your XDebug-client then the web-site wouldn't render immediately. But in your case the GET-parameters are just ignored b/c they have no meaning for your Apache/PHP-server as they don't know anything about some XDebug-session you would like to start.

3) Your solution approaches seem very complicated to me. I would keep at simple as possible first and see how that works. For example "xdebug.idekey="netbeans-xdebug" is usually not necassary for a first setup.

Those are my two cents

Best Raffael

Raffael
  • 19,547
  • 15
  • 82
  • 160