调试 IDE 与 XDebug 的端口连接:“等待连接”

发布于 2024-09-27 20:13:01 字数 3558 浏览 10 评论 0原文

前言

与许多人一样,我在调试 IDE 与 XDebug 的连接上花费的时间比使用 XDebug 调试程序的时间还要多。 我已经让它反复工作,但每隔一段时间我就会遇到常见的“等待连接”问题。我无法定位导致 XDebug 工作或失败的原因。我已经使用 ubuntu 两年了;我既不是新手,也不是 strace 专家。 我做错了什么?如何更好地调试 IDE 与 XDebug 的连接?


Xdebug v2.1.0设置

  • Ubuntu 10.10
  • Netbeans 6.9.1
  • 使用 Suhosin-Patch
  • PHP 5.3.3-1ubuntu9 ,并使用 2010 年 9 月 20 日从源代码构建的 debugclient xdebug.org 上定制的安装说明脚本
  • Apache Apache/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"
      

过程

问题

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

调试 XDebug

首先,在“Waiting to Connect”消息仍然存在的情况下,我将尝试使用 netstat 来挖掘端口 9000,这类似于

$ netstat -an | grep 9000
tcp6       0      0 :::9000                 :::*                    LISTEN     

我关闭了 IDE 并尝试使用两个文件可帮助弄清楚发生了什么: {webroot}/index.php 包含 ,并且 {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);
?>

当我启动 XDebug debugclient 并打开 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

虽然这两个似乎都表明已建立连接,但网页上显示“无法绑定”,我无法解释。我按 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 

其他时候,我会重新启动计算机,启动终端,然后发现:

$ 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

我对网络和 Linux 内部结构不太熟悉,看不出这意味着什么。显然有东西正在使用端口9000。这是什么意思?请注意,尽管我在 php.ini 中进行了设置:

$ cat /var/log/xdebug.log
cat: /var/log/xdebug.log: No such file or directory

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浪推晚风 2024-10-04 20:13:01

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

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.

青瓷清茶倾城歌 2024-10-04 20:13:01

请阅读此主题。

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

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

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.

£烟消云散 2024-10-04 20:13:01

嗯,我的开发设置与您的有所不同,但我非常清楚这个问题。事实上,我刚刚解决了这个问题……这次我的 Fireeall 阻止了 XDebug 用于与我的 IDE 通信的端口。

阅读您的帐户时,我想到了一些事情:

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

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

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

这些是我的两分钱

最好
拉斐尔

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文