php netbeans 显示“等待连接(netbeans-xdebug)”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17613726/
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 16:10:57  来源:igfitidea点击:

netbeans shows "Waiting For Connection (netbeans-xdebug)"

phpwindowsapachenetbeansxdebug

提问by pasluc74669

need help to configure xdebug, for debugging projects from IDE netbeans.

需要帮助来配置 xdebug,以便从 IDE netbeans 调试项目。

These are the features of my components:

这些是我的组件的功能:

XAMPP 1.8.2

XAMPP 1.8.2

PHP: 5.4.16

PHP:5.4.16

netbeans: 7.3.1

网豆:7.3.1

Apache: 2.4.4 (Win32)

Apache:2.4.4 (Win32)

this is the final part of my php.ini file:

这是我的 php.ini 文件的最后一部分:

 [XDebug]
 zend_extension = "C:\xampp\php\ext\php_xdebug-2.2.3-5.4-vc9-nts.dll"
 ;xdebug.profiler_append = 0
 ;xdebug.profiler_enable = 1
 ;xdebug.profiler_enable_trigger = 0
 xdebug.profiler_output_dir = "C:\xampp\tmp"
 ;xdebug.profiler_output_name = "cachegrind.out.%t-%s"
 xdebug.remote_enable = 1
 xdebug.remote_handler = "dbgp"
 xdebug.remote_host = "127.0.0.1"
 ;xdebug.trace_output_dir = "C:\xampp\tmp"

when I run phpinfo(), there is no xdebug installed, and when I debug a project from netbeans, it says "Waiting For Connection (netbeans-xdebug)".

当我运行 phpinfo() 时,没有安装 xdebug,当我从 netbeans 调试项目时,它显示“等待连接(netbeans-xdebug)”。

can someone help me to configure it? would be very appreciated.

有人可以帮我配置吗?将不胜感激。

thanks in advance.

提前致谢。

回答by Johnson T A

Have you rectified the issue ? If not then please try this.

你纠正了这个问题吗?如果没有,请尝试这个。

1.) php.inifile content

1.)php.ini文件内容

[xDebug]
zend_extension = "c:\xampp\php\ext\php_xdebug-2.2.3-5.4-vc9.dll"
xdebug.remote_autostart=on
xdebug.remote_enable=on
xdebug.remote_enable=1
xdebug.remote_handler="dbgp"
;xdebug.remote_host="localhost:81"
xdebug.remote_host=192.168.1.5
;xdebug.remote_connect_back=1
xdebug.remote_port=9000
xdebug.remote_mode=req
xdebug.idekey="netbeans-xdebug"

xdebug.remote_host=192.168.1.5- This is the IPv4 address of my system, I changed to this because I couldn't debug with localhostand 127.0.0.1.

xdebug.remote_host=192.168.1.5- 这是我系统的IPv4地址,我改成这个是因为我不能用localhost和调试127.0.0.1

in NetBeans IDE, open Tools-> Options -> PHP -> Debugging. The values of debugger port and Session Id should match with the port and idekey specified in php.ini.

在 NetBeans IDE 中,打开Tools-> Options -> PHP -> Debugging. 调试器端口和会话 ID 的值应与 中指定的端口和 idekey 匹配php.ini

Now save php.ini, restart Apache and try to debug.

现在保存 php.ini,重启 Apache 并尝试调试。

Thanks Johnson

谢谢约翰逊

回答by rightstuff

When Netbeans starts a Debugging session, it starts two Listeners, one on 0.0.0.0:9000 (all IPv4 IPs the system has), and the other on the IPv6 interface.

当 Netbeans 启动调试会话时,它会启动两个侦听器,一个在 0.0.0.0:9000(系统拥有的所有 IPv4 IP)上,另一个在 IPv6 接口上。

If Netbeans and the Web Server are on the same system, ideally XDebug would be configured to send the data back to 127.0.0.1:9000, on which NetBeans would be listening on (and only per session)...

如果 Netbeans 和 Web 服务器在同一系统上,理想情况下 XDebug 将被配置为将数据发送回127.0.0.1:9000NetBeans 将侦听的(并且仅每个会话)...

xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_autostart=0
xdebug.remote_connect_back=0

If for whatever reason XDebug is not able to report back to 127.0.0.1, or Netbeans is not listening on 127.0.0.1, you can configure XDebug to send the data back to the $_SERVER['REMOTE_ADDR']of the original request...

如果由于某种原因 XDebug 无法返回报告127.0.0.1,或者 Netbeans 没有监听127.0.0.1,您可以配置 XDebug 将数据发送回$_SERVER['REMOTE_ADDR']原始请求...

xdebug.remote_connect_back=1

This way you don't have to specify the exact IP (i.e., as in the above answer the LAN IP: 192.168.1.5). The downside here is that any source can connect.

这样您就不必指定确切的 IP(即,如上述回答中的 LAN IP: 192.168.1.5)。这里的缺点是任何来源都可以连接。

If you have further trouble, this...

如果您有进一步的麻烦,这...

xdebug.remote_autostart=1

... will also start the debugging process for allrequests, and not just for the ones with the proper session start query or cookie. The downside here is that all requests will initiate debug data collection and reporting back (making everything slower, and generating more data).

...还将为所有请求启动调试过程,而不仅仅是针对具有正确会话启动查询或 cookie 的请求。这里的缺点是所有请求都将启动调试数据收集和报告(使一切变慢,并生成更多数据)。

Though from what I've gathered, the majority of these "Waiting For Connection (netbeans-xdebug)" issues on Windows (with XAMPP, Wamp-Server, etc) are usually a result of Windows Firewall and McAfee (or other firewall and anti-virus software) blocking the connection...

尽管从我收集到的信息来看,Windows(使用 XAMPP、Wamp-Server 等)上的大多数“等待连接 (netbeans-xdebug)”问题通常是由 Windows 防火墙和 McAfee(或其他防火墙和反-病毒软件)阻止连接...

Source: Netbeans "Waiting For Connection (netbeans-xdebug)" Issue

来源:Netbeans“等待连接(netbeans-xdebug)”问题

回答by Jitendra Sawant

I am a .Net programmer and very new to PHP. Recently I was trying to host an open source PHP application on my machine(Windows). After the Struggle for 5-6 days I will list the steps which worked for me.

我是一名 .Net 程序员,对 PHP 非常陌生。最近我试图在我的机器(Windows)上托管一个开源 PHP 应用程序。经过 5-6 天的奋斗后,我将列出对我有用的步骤。

I uninstalled every previous installations of XAMPP and NetBeans and proceeded with fresh installations.

我卸载了之前所有的 XAMPP 和 NetBeans 安装,然后继续进行全新安装。

This might not be the solution for everyone but it worked for me and I hope it helps someone.

这可能不是每个人的解决方案,但它对我有用,我希望它可以帮助某人。

  1. install XAMPP

  2. install netbeans for PHP.

  3. Open IIS and stop it. It is running on port 80 by default.(I am running XAMPP on port 80 i.e. default, Running on other port might need additional configuration settings)

  4. Open XAMPP control panel and start Apache. If port 80 is free no problem should arise.

  5. Open localhost in browser in should display XAMPP home page.

  6. open phpinfo()link on the left pane and copy all the contents on page. Go to: http://xdebug.org/wizard.phpand paste all the content in TextBox and click Analyze my phpinfo output. It will diplay you the Xdebug file suitable for your configuration.

  7. Download the given Xdebug dll and copy it in C:\xampp\php\ext(Xampp being the default Xampp installation directory)

  8. Goto XAMPP control panel, click on Config button in front of Apache and select php.in,

  9. Find line similar or exacly like,

  1. 安装 XAMPP

  2. 为 PHP 安装 netbeans。

  3. 打开 IIS 并停止它。默认情况下,它在端口 80 上运行。(我在端口 80 上运行 XAMPP,即默认值,在其他端口上运行可能需要额外的配置设置)

  4. 打开 XAMPP 控制面板并启动 Apache。如果端口 80 空闲,则不会出现问题。

  5. 在浏览器中打开 localhost 应该会显示 XAMPP 主页。

  6. 打开phpinfo()左窗格中的链接并复制页面上的所有内容。转到:http: //xdebug.org/wizard.php并将所有内容粘贴到 TextBox 中,然后单击分析我的 phpinfo 输出。它将显示适合您配置的 Xdebug 文件。

  7. 下载给定的 Xdebug dll 并将其复制到C:\xampp\php\ext(Xampp 是默认的 Xampp 安装目录)

  8. 转到 XAMPP 控制面板,单击 Apache 前面的 Config 按钮并选择php.in

  9. 查找相似或完全相似的行,

;zend_extension = "C:\xampp\php\ext\php_xdebug.dll"

;zend_extension = "C:\xampp\php\ext\php_xdebug.dll"

(Semicolon means it is commented)

(分号表示已注释)

Remove the semicolon and replace the path with the path of dll you just copied like:

删除分号并将路径替换为您刚刚复制的 dll 路径,如下所示:

zend_extension = "C:\xampp\php\ext\php_xdebug-2.3.2-5.4-vc9.dll"
  1. Similarly find lines

    ;xdebug.remote_enable = 0 ;xdebug.remote_handler = "dbgp"

  1. 同样找行

    ;xdebug.remote_enable = 0 ;xdebug.remote_handler = "dbgp"

remove semicolons in front of both lines and make remote_enable = 1

删除两行前面的分号并制作 remote_enable = 1

xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
  1. Restart Apache server.

  2. Copy your website code under C:/XAMPP/htdocs/(your_website)/that means your index.phpshould be at C:/XAMPP/htdocs/(your_website)/index.php

  3. Open Netbeans select New project -> PHP -> PHP project from existing source and select the folder you just copied in htdocs folder. Set it to run on Local web server.

  4. Set a breakpoint on first line of index.phpand debug.

  1. 重新启动 Apache 服务器。

  2. 复制您的网站代码,C:/XAMPP/htdocs/(your_website)/这意味着您index.php应该在C:/XAMPP/htdocs/(your_website)/index.php

  3. 打开 Netbeans 选择 New project -> PHP -> PHP project from existing source 并选择刚刚复制到 htdocs 文件夹中的文件夹。将其设置为在本地 Web 服务器上运行。

  4. index.php调试的第一行设置断点。

That's it.

就是这样。

Additional settings were suggested on various different posts but above mentioned steps worked perfectly for me.

在各种不同的帖子中建议了其他设置,但上述步骤对我来说非常有效。

回答by Beachhouse

I want to mention something here about xdebug.remote_host

我想在这里提一些关于 xdebug.remote_host 的事情

xdebug.remote_host="127.0.0.1"

Is Not valid. It may work in some cases, but the quotes can also cause issues. Most people don't have issues when using IP addresses in quotes, but this sets a bad precedent. It makes people think that if you want to use a hostname or URL you need to put it in quotes. This is incorrect, urls in quotes will not work.

无效。它可能在某些情况下有效,但引号也可能导致问题。大多数人在引号中使用 IP 地址时没有问题,但这开创了一个不好的先例。它让人们认为如果你想使用主机名或 URL,你需要把它放在引号中。这是不正确的,引号中的 url 将不起作用。

If you want to debug using a url, you can do this by just putting the url after the equals like this:

如果要使用 url 进行调试,只需将 url 放在等号之后即可,如下所示:

xdebug.remote_host=subdomain.mydomain.com

I also want to mention that if you have a port number, don't add it. This doesn't work:

我还想提一下,如果您有端口号,请不要添加它。这不起作用:

xdebug.remote_host=subdomain.mydomain.com:9000

This is what you want to do:

这是你想要做的:

xdebug.remote_host=subdomain.mydomain.com
xdebug.remote_port=9000

If you do this, I also caution you make sure remote_connect_back is disabled. Like this:

如果你这样做,我还要提醒你确保 remote_connect_back 被禁用。像这样:

xdebug.remote_connect_back=0

or you can ommit it entirely, like this:

或者您可以完全省略它,如下所示:

;xdebug.remote_connect_back=1

If remote_connect_back is enabled, it will try and pull your IP address from the incoming connection and ignore the remote_host and port setting.

如果启用了 remote_connect_back,它将尝试从传入连接中提取您的 IP 地址并忽略 remote_host 和端口设置。

Xdebug uses plain old TCP to make connections. This is not HTTP. This means tools like Fiddler will not show any packets or information on debugging. If you need to debug, and see if the server is making a call to your IDE there are a few ways you can go about checking.

Xdebug 使用普通的旧 TCP 来建立连接。这不是 HTTP。这意味着像 Fiddler 这样的工具不会显示任何有关调试的数据包或信息。如果您需要调试,并查看服务器是否正在调用您的 IDE,您可以通过几种方法进行检查。

Wireshark will allow you to see TCP traffic. Also if you are on Windows, Microsoft Message Analyzer can also monitor TCP.

Wireshark 将允许您查看 TCP 流量。此外,如果您使用的是 Windows,Microsoft Message Analyzer 也可以监视 TCP。

But, if all you are trying to do is remove your IDE is a possible cause of remote debugging problems, I suggest instead you start a local TCP server.

但是,如果您尝试做的只是删除可能导致远程调试问题的 IDE,我建议您改为启动本地 TCP 服务器。

This is a great free java program to start a TCP server: http://sockettest.sourceforge.net/

这是一个很棒的免费 Java 程序来启动 TCP 服务器:http: //sockettest.sourceforge.net/

How to start a TCP Server

如何启动 TCP 服务器

In the IP Address section, just list 127.0.0.1 or leave it at 0.0.0.0. Then list the port number, which is usually defaulted to 9000 for xdebug.

在 IP 地址部分,只需列出 127.0.0.1 或将其保留为 0.0.0.0。然后列出端口号,xdebug 通常默认为 9000。

Once the TCP server is running, open your remote webpage with an xdebug_break(); function call in it. This will tell xdebug on the remote server to start debugging on whatever server and port you listed in your php.ini.

TCP 服务器运行后,使用 xdebug_break() 打开远程网页;里面的函数调用。这将告诉远程服务器上的 xdebug 在您在 php.ini 中列出的任何服务器和端口上开始调试。

Watch the socket server and see if you get a connection. The first data sent should look something like this:

观察套接字服务器,看看是否有连接。发送的第一个数据应如下所示:

<init appid="APPID"
      idekey="IDE_KEY"
      session="DBGP_COOKIE"
      thread="THREAD_ID"
      parent="PARENT_APPID"
      language="LANGUAGE_NAME"
      protocol_version="1.0"
      fileuri="file://path/to/file">

If you have made it this far, remote debugging is working! Just stop the server and setup your IDE to listen on that port!

如果你已经做到了这一步,远程调试就可以了!只需停止服务器并设置您的 IDE 以侦听该端口!



If you are like most of us, your developer machine is behind a router with NAT. This means that everyone in your office has the same public IP address. This is a problem because when xdebug contact that IP address to start debugging, it hits the router, and not your computer. The router can be configured to pass certain port numbers to individual computers, but you may not want to do that as that port will be open until you change your router settings back.

如果您和我们大多数人一样,您的开发者机器位于带有 NAT 的路由器后面。这意味着您办公室中的每个人都拥有相同的公共 IP 地址。这是一个问题,因为当 xdebug 联系该 IP 地址以开始调试时,它会访问路由器,而不是您的计算机。路由器可以配置为将某些端口号传递给单个计算机,但您可能不想这样做,因为在您更改路由器设置之前,该端口将打开。

Another option is to use SSH. There is a great example of how to do this here: http://stuporglue.org/setting-up-xdebug-with-netbeans-on-windows-with-a-remote-apache-server/#attachment_1305

另一种选择是使用 SSH。这里有一个很好的例子说明如何做到这一点:http: //stuporglue.org/setting-up-xdebug-with-netbeans-on-windows-with-a-remote-apache-server/#attachment_1305

My preferred option is to use Ngrok. Ngrok is a great tool for redirecting http, https and TCP traffic. In order to use the TCP redirect function you need to sign up for a free account.

我的首选是使用Ngrok。Ngrok 是一个很好的重定向 http、https 和 TCP 流量的工具。为了使用 TCP 重定向功能,您需要注册一个免费帐户。

Once you have signed up for an account, and added your API key to your computer run this command on the computer that your IDE is on:

注册帐户并将 API 密钥添加到计算机后,在 IDE 所在的计算机上运行以下命令:

ngrok tcp 9000

This will open a tcp (not http) tunnel from the ngrok server to whatever machine you ran the command on. I am using port 9000, you can change this port if your IDE is configured for a different Xdebug port.

这将打开从 ngrok 服务器到您运行命令的任何机器的 tcp(不是 http)隧道。我正在使用端口 9000,如果您的 IDE 配置为不同的 Xdebug 端口,您可以更改此端口。

This is what you should see:

这是你应该看到的:

Ngrok tcp tunnel open

Ngrok tcp隧道打开

You will need to see what the url is for the TCP tunnel that was opened. In this example it is:

您需要查看打开的 TCP 隧道的 URL。在这个例子中是:

0.tcp.ngrok.io:14904

For this session, the Xdebug setting on your server should be this:

对于此会话,您服务器上的 Xdebug 设置应为:

xdebug.remote_host=0.tcp.ngrok.io
xdebug.remote_port=14904

The URL and port will change each time ngrok is launched. If you want to have the same url and port, you have to upgrade to a paid account. Make sure to restart apache after you make changes to your php.ini.

每次启动 ngrok 时,URL 和端口都会更改。如果您想拥有相同的网址和端口,则必须升级到付费帐户。更改 php.ini 后,请确保重新启动 apache。

回答by Ryan

I just spent hours reading so many answers on this page and others like it, and nobody mentioned what ended up being the solution for me:

我只是花了几个小时阅读此页面上的许多答案以及其他类似的答案,但没有人提到最终对我来说是解决方案:

Make Sure Your Chosen Port Settings Match in All 3 Locations

确保您选择的端口设置在所有 3 个位置都匹配

My problem was that there are THREE places that the chosen port needs to match. Two of mine said 9001 and one said 9000. I changed them all to 9000.

我的问题是所选端口需要匹配三个地方。我的两个说9001,一个说9000。我把它们都改成了9000。

That was the problem and why Netbeans would only say “Waiting For Connection (netbeans-xdebug)”.

这就是问题所在,也是为什么 Netbeans 只会说“等待连接 (netbeans-xdebug)”。

The 3 port setting locations are:

3个端口设置位置是:

  • php.ini(xdebug.remote_port=9000)
  • project properties > Run Configuration > Advanced
  • Netbeans > Tools > Options > PHP > Debugging
  • php.ini( xdebug.remote_port=9000)
  • 项目属性 > 运行配置 > 高级
  • Netbeans > 工具 > 选项 > PHP > 调试

回答by Tim Stollberg

Check also the "windows" firewall settings.

还要检查“windows”防火墙设置。

For me it doesn't worked because my LAN network was declared as "Public network". After i switched it to "Work network" it worked fine.

对我来说它不起作用,因为我的 LAN 网络被声明为“公共网络”。在我将它切换到“工作网络”后,它工作正常。

回答by Richard Lovell

I'm on Windows with xampp and changed the [XDebug] section of my php.ini (at the bottom) to the following to get it working:

我在 Windows 上使用 xampp 并将我的 php.ini(底部)的 [XDebug] 部分更改为以下内容以使其正常工作:

zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000

Sourced from the Netbeans wiki here: http://wiki.netbeans.org/HowToConfigureXDebug

来自此处的 Netbeans wiki:http: //wiki.netbeans.org/HowToConfigureXDebug

If you have Apache running, remember to restart it after configuring XDebug and saving php.ini.

如果你有Apache运行,记得在配置XDebug并保存php.ini后重启它。

回答by shires-boy

Having correctly set up the php.ini file, netbeans, port forwarding on the router, I was still getting the wretched "waiting for connection (netbeans-xdebug). I eventually noticed on the netbeans page "Do not forget to set output_buffering = Off in your php.ini file".

在路由器上正确设置了 php.ini 文件、netbeans、端口转发后,我仍然遇到了“等待连接(netbeans-xdebug)”的问题。我最终在 netbeans 页面上注意到“不要忘记设置 output_buffering = Off在您的 php.ini 文件中”。

So I checked the /etc/php/7.x/apache2/php.ini file and sure enough it's value was 4096. So I reset output_buffering=Off and lo it worked !!!

所以我检查了 /etc/php/7.x/apache2/php.ini 文件,果然它的值是 4096。所以我重置 output_buffering=Off 并且它工作了!

Hope this helps someone, as the message implies it is a connection error rather than a configuration error.

希望这对某人有所帮助,因为该消息暗示这是连接错误而不是配置错误。

回答by John Sarris

Adding this did work for me:

添加这个对我有用:

xdebug.idekey=netbeans-xdebug   

回答by user2701551

In my case the Apache log showed a PHP warning about not having set date.timezone. Xdebug/netbeans began working as soon as I set it in php.ini and restarted apache.

在我的例子中,Apache 日志显示了一个关于没有设置 date.timezone 的 PHP 警告。一旦我在 php.ini 中设置 Xdebug/netbeans 并重新启动 apache,它就开始工作。

date.timezone = America/Los_Angeles

This is PHP 5.5.

这是 PHP 5.5。