English 中文(简体)
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?

问题回答

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.

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.

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





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签