php 调试 IDE 与 XDebug 的端口连接:“Waiting to Connect”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3955226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:33:33  来源:igfitidea点击:

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

phpnetbeansidexdebugnetstat

提问by P. Myer Nore

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?

与许多人一样,我花在调试 IDE 与 XDebug 的连接上的时间比使用 XDebug 调试我的程序所花的时间要多。我已经让它反复工作,但每隔一段时间我都会遇到常见的“等待连接”问题。我无法定位导致 XDebug 工作或失败的原因。我已经使用 ubuntu 两年了;我既不是菜鸟也不是 strace 大师。我究竟做错了什么?如何更好地调试 IDE 与 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"
      
  • Ubuntu 10.10
  • Netbeans 6.9.1
  • PHP 5.3.3-1ubuntu9 与 Suhosin-Patch
  • 2010 年 9 月 20 日使用xdebug.org 上定制安装说明脚本从源代码构建的带有 debugclient 的 Xdebug v2.1.0
  • 阿帕奇阿帕奇/2.2.16
  • /etc/php5/apache2/php.ini 和 /etc/php5/cli/php.ini 都有:
    • 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.”

我无法解释导致问题的原因或问题出现的时间。它开始于我尝试调试我的项目时,这会导致我选择的开发浏览器 (Chrome) 以参数XDEBUG_SESSION_START=netbeans-xdebug. 这会导致页面在 chrome 中正常呈现,而 Netbeans 仅报告“等待连接”。

Debugging XDebug

调试 XDebug

First, with the “Waiting to Connect” message still alive, I'll try to use netstat to dig around port 9000, which goes something likethis:

首先,用“等待连接”消息还活着,我会尝试用netstat来挖过来端口9000,去这样:

$ 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.phpcontains <?php phpinfo(); ?>, and {webroot}/dbgtest.phpcontains the XDebug installation check script:

我关闭了我的 IDE 并尝试使用两个文件来帮助找出发生了什么:{webroot}/index.phpcontains<?php phpinfo(); ?>{webroot}/dbgtest.php包含XDebug 安装检查脚本

<?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 debugclientand open http://127.0.0.1/dbgtest.php?XDEBUG_SESSION_START=mysession, I'll usually get the regular outputand then verify XDebug is connected to the script with netstat in another terminal:

当我启动 XDebugdebugclient并打开时http://127.0.0.1/dbgtest.php?XDEBUG_SESSION_START=mysession,我通常会得到常规输出,然后在另一个终端中使用 netstat 验证 XDebug 是否连接到脚本:

$ 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.phpand 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:

虽然这两个似乎都表明已经建立了连接,但网页上写着“无法绑定”,我无法解释。我 Ctrl-c 退出 debugclient,此时 netstat 验证端口 9000 没有活动。我启动 Netbeans,打开{webroot}/index.php并启动调试器,它打开http://127.0.0.1/index.php. 然后调试器通常会正常启动。我停止调试器,回到我的项目,这就是问题真正变得烦人的地方:有时,我可以像往常一样继续调试我的项目,而其他时候,问题再次出现,而“等待Connect”标志显示,netstat 显示:

$ 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 somethingis using port 9000. What does this mean? Note that despite my settings in php.ini:

我对网络和 linux 内部结构不够熟悉,无法了解这意味着什么。显然有些东西正在使用端口 9000。这是什么意思?请注意,尽管我在 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?

调试IDE和XDebug之间的连接的正确方法是什么?

回答by reh

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.

如果您偶然使用 Cisco VPN 客户端,这可能是一个原因。它带有一个防火墙,即使客户端没有启动,它也始终处于开启状态。它可以在选项菜单中取消选中。

回答by richrosa

Please read this thread.

请阅读此线程。

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

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.

最后的解决方法是将 net.ipv6.bindv6only = 0 添加到文件 /etc/sysctl.d/bindv6only.conf 中,然后重新启动。之后 Xdebug 工作正常。

回答by Raffael

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.

好吧,我的开发设置与您的有些不同,但我非常了解这个问题。事实上,我刚刚解决了它……这次我的 Fireeall 阻止了 XDebug 用来与我的 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?

1) “我无法解释导致问题的原因或问题出现的时间。” 这是一个非常重要的陈述 b/c,众所周知,技术解决方案严格取决于潜在问题是否总是或有时以看似随机的方式发生。那么……您有时可以以这种方式执行 XDebugging 还是从不执行?

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.

2) 当您的 IDE 正在等待并且您的浏览器立即呈现站点时,那么我猜您的 IDE 有问题告诉您的 XDebug-server 启动。B/c 如果 XDebug 将启动并且无法连接回您的 XDebug 客户端,则该网站不会立即呈现。但是在您的情况下,GET 参数只是被忽略了 b/c,它们对您的 Apache/PHP 服务器没有意义,因为它们对您想要启动的某些 XDebug 会话一无所知。

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.

3)你的解决方法对我来说似乎很复杂。我会首先尽可能保持简单,看看它是如何工作的。例如,"xdebug.idekey="netbeans-xdebug" 通常不是第一次设置所必需的。

Those are my two cents

这是我的两分钱

Best Raffael

最佳拉斐尔