php 根据外部请求在 Netbeans 中启动 XDebug
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1531391/
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
Launch XDebug in Netbeans on an external request
提问by John Carter
I'm using Netbeans 6.7 and XDebug to debug a PHP site on my machine, launching the request from within Netbeans (Project->Debug). This works fine, and is very useful.
我正在使用 Netbeans 6.7 和 XDebug 在我的机器上调试 PHP 站点,从 Netbeans(项目->调试)中启动请求。这很好用,而且非常有用。
My question is: Is it possible to attach the debugger to any request that comes in, rather just those I launch from within Netbeans?
我的问题是:是否可以将调试器附加到任何传入的请求,而不是我从 Netbeans 中启动的请求?
ie, instead of clicking "Debug", put Netbeans into a mode whereby the debugger is launched and attaches to the next request that comes in.
即,不是单击“调试”,而是将 Netbeans 置于启动调试器并附加到进入的下一个请求的模式中。
I have a feeling this may be a stupid question, but if it is possible, that'd be great.
我有一种感觉,这可能是一个愚蠢的问题,但如果可能的话,那就太好了。
Edit:A bit more information
编辑:更多信息
My system (Ubuntu 9.04) is set up as follows:
我的系统(Ubuntu 9.04)设置如下:
Contents of /etc/php5/conf.d/xdebug.ini
的内容 /etc/php5/conf.d/xdebug.ini
zend_extension=/usr/lib/php5/20060613/xdebug.so
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.idekey=netbeans-xdebug
Netbeans PHP debugging options are at the defaults:
Netbeans PHP 调试选项为默认值:
Debugger Port: 9000
Session ID: netbeans-xdebug
Stop at the First Line: ticked
My /etc/hostsfile redirects www.mywebsite.comto localhost
我的/etc/hosts文件重定向www.mywebsite.com到localhost
If I click on the debug button in Netbeans, then Firefox is launched with the address http://www.mywebsite.com?XDEBUG_SESSION_START=netbeans-xdebug, and the debugger works as expected.
如果我单击 Netbeans 中的调试按钮,则会使用地址 启动 Firefox http://www.mywebsite.com?XDEBUG_SESSION_START=netbeans-xdebug,并且调试器会按预期工作。
But if I just browse to http://www.mywebsite.com?XDEBUG_SESSION_START=netbeans-xdebug, this doesn't start the debugger in Netbeans.
但是如果我只是浏览到http://www.mywebsite.com?XDEBUG_SESSION_START=netbeans-xdebug,这不会在 Netbeans 中启动调试器。
I've also tried setting xdebug.remote_host=www.mywebsite.com, but that makes no difference.
我也试过设置xdebug.remote_host=www.mywebsite.com,但这没什么区别。
Also, I've enabled xdebug.remote_log, and that's showing information for when I start from within netbeans, but nothing for external requests. So I don't think XDebug is seeing the external requests at all.
此外,我已启用xdebug.remote_log,这显示了我何时从 netbeans 内启动的信息,但没有显示外部请求的信息。所以我认为 XDebug 根本没有看到外部请求。
回答by ax.
go to project properties> run configuration> advanced> debug urland check do not open web browser(*). do notset the host under debugger proxy. save these settings. in the project window, on your project: right mouse click> debug(this starts listening for debug connections). no browser is started. enter http://www.mywebsite.com?XDEBUG_SESSION_START=netbeans-xdebugin your browser. it should break in netbeans. at least that's what happens here :)
转到项目属性>运行配置>高级>调试 url并检查不要打开 Web 浏览器(*)。千万不能设置在主机的调试器代理。保存这些设置。在项目窗口中,在您的项目上:右键单击>调试(这将开始侦听调试连接)。没有启动浏览器。http://www.mywebsite.com?XDEBUG_SESSION_START=netbeans-xdebug在浏览器中输入。它应该在 netbeans 中崩溃。至少这就是这里发生的事情:)
(*) you might also have to set a path mapping- for me, it works without
(*) 您可能还必须设置路径映射- 对我来说,它无需
回答by Pada
By default xdebug will not attempt to connect to the remote host when the 'XDEBUG_SESSION_START' Cookie/URL argument wasn't specified. You can enable xdebug to be "always on", by setting the xdebug.remote_autostart to 1 in the php.ini.
默认情况下,当未指定 'XDEBUG_SESSION_START' Cookie/URL 参数时,xdebug 不会尝试连接到远程主机。您可以通过在 php.ini 中将 xdebug.remote_autostart 设置为 1 来启用 xdebug 为“始终开启”。
Furthermore, you would have to start the PHP debugger in NetBeans for this to work. I haven't found a better solution yet, but you can have the PHP debugger listening for incoming connections by starting to debug a random file (use CTRL+SHIFT+F5 to start debugging a file) and then continuing (by pressing F5) once it stopped at the breakpoint. The Netbeans debugger should run until you actually stop it.
此外,您必须在 NetBeans 中启动 PHP 调试器才能使其工作。我还没有找到更好的解决方案,但您可以让 PHP 调试器通过开始调试随机文件(使用 CTRL+SHIFT+F5 开始调试文件)然后继续(按 F5)一次来侦听传入连接它停在断点处。Netbeans 调试器应该一直运行,直到您真正停止它为止。
Update: due to NetBeans checking the session id (XDEBUG_SESSION_START), you have to set the idekey variable too. eg:
更新:由于 NetBeans 检查会话 ID (XDEBUG_SESSION_START),您也必须设置 idekey 变量。例如:
xdebug.remote_autostart = 1
xdebug.idekey = "netbeans-xdebug"
回答by Pete855217
I had a similar problem (on NetBeans, Mac OSX), after upgrading PHP and compiling/installing xdebug. phpinfo showed xdebug as loaded, but it still wouldn't connect, and after trying everything listed above still had no success. Then I tried reducingthe number of parameters set in my PHP.ini file back to the minimum required. This seemed to sort the problem out for me.
在升级 PHP 并编译/安装 xdebug 后,我遇到了类似的问题(在 NetBeans、Mac OSX 上)。phpinfo 显示 xdebug 已加载,但它仍然无法连接,并且在尝试了上面列出的所有内容后仍然没有成功。然后我尝试将PHP.ini 文件中设置的参数数量减少到所需的最小值。这似乎为我解决了问题。
; REMOVED (commented) the following
; xdebug.remote_log=/myfile.log
;xdebug.extended_info = off
;xdebug.auto_trace=1
;xdebug.trace_output_dir=/mydir/myphptracefile.txt
;xdebug.trace_output_name=php_trace.%c
;xdebug.collect_params=4
I also renamed the default xdebug.idekey from netbeans-xdebug to default, then back again.
我还将默认的 xdebug.idekey 从 netbeans-xdebug 重命名为默认值,然后再次返回。
After restarting Apache, xdebug started working again: I'm not sure what exactly fixed it, but a good starting point might be to just start with the minimum number of xdebug settings in your php.ini file, then slowly add more if you need them.I suspect it may have had something to do with the trace settings, but can't be sure.
重新启动 Apache 后,xdebug 再次开始工作:我不确定究竟是什么修复了它,但一个好的起点可能是从 php.ini 文件中的最少 xdebug 设置开始,然后根据需要慢慢添加更多他们。我怀疑它可能与跟踪设置有关,但不能确定。
The basic settings I ended up using were:
我最终使用的基本设置是:
xdebug.remote_enable=on
xdebug.remote_port=9000
xdebug.remote_host=localhost
xdebug.remote_handler=dbgp
xdebug.idekey=netbeans-xdebug
It's also a good idea to compile debugclient (in the xdebug source package), and check debugging on the command line as this will tell you whether xdebug can at least run independently of your IDE.
编译 debugclient (在 xdebug 源包中),并在命令行上检查调试也是一个好主意,因为这将告诉您 xdebug 是否至少可以独立于您的 IDE 运行。
回答by timmow
Not sure about Netbeans, but any other IDE I have used is always listening for a debug connection. You can start a new debug session from xdebug by appending the query string ?XDEBUG_SESSION_START=nameto the url. If Netbeans is listening, this should then kick off a new debug session.
不确定 Netbeans,但我使用过的任何其他 IDE 总是在侦听调试连接。您可以通过将查询字符串附加?XDEBUG_SESSION_START=name到 url 来从 xdebug 启动新的调试会话。如果 Netbeans 正在侦听,则应启动新的调试会话。
See http://xdebug.org/docs/remote#browser_sessionfor more details
有关更多详细信息,请参阅http://xdebug.org/docs/remote#browser_session

