用 Eclipse 调试 PHP?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1582897/
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
Debug PHP with Eclipse?
提问by Nick Heiner
What is the best way to debug PHP with Eclipse? Specifically, I'm trying to work through some issues on a Drupal 6 installation.
使用 Eclipse 调试 PHP 的最佳方法是什么?具体来说,我正在尝试解决 Drupal 6 安装中的一些问题。
I like Eclipse's debugging for Java. Is there a way to do the same for PHP?
我喜欢 Eclipse 的 Java 调试。有没有办法对 PHP 做同样的事情?
回答by Pascal MARTIN
I've never used Eclipse to develop in JAVA, but if you are asking about a graphical debugger that allows to set up breakpoints, go through the current stack trace, see content of variables, and all that, there is (at least one) a solution:
我从未使用过 Eclipse 在 JAVA 中进行开发,但是如果您询问允许设置断点、查看当前堆栈跟踪、查看变量内容以及所有这些的图形调试器(至少有一个)一个办法:
You can use the Xdebugextension, and Eclipse PDTas IDE : the second one is able to use the first one as debugger, and provides an interface for it -- kind of what you might expect if you have used a visual debugger in other languages/IDE.
您可以使用Xdebug扩展和Eclipse PDT作为 IDE:第二个可以使用第一个作为调试器,并为其提供一个界面——如果您使用其他语言的可视化调试器,您可能会期望/IDE。
I've used this combination a couple of times with Drupal, to see what was executed, in which order, how, and all that (not easy to get "by hand", with the hooks mecanism), and it definitly works pretty well.
我已经在 Drupal 中多次使用这种组合,以查看执行的内容、顺序、方式以及所有这些(不容易“手动”获得,使用钩子机制),并且它绝对工作得很好.
There are tutorials available on the net that explain how to setup both of those to get the debugger working. For instance :
网上有一些教程可以解释如何设置这两者以使调试器正常工作。例如 :
- How To Setup a Free PHP Debugger using Eclipse PDT + XDebug
- Setting up Eclipse to Debug Drupal with XDebug(unfortunatly, the screenshots are missing)
- Or (in french, but with screenshots ; so, might be helpful evn if not easy to understand) :
- 如何使用 Eclipse PDT + XDebug 设置免费的 PHP 调试器
- 设置 Eclipse 以使用 XDebug 调试 Drupal (不幸的是,缺少屏幕截图)
- 或者(用法语,但有截图;所以,如果不容易理解,可能会有所帮助):
And here is a screenshot of what it can look like (here, I've set a breakpoint somewhere is the backoffice of Dotclear):
这是它的外观截图(在这里,我在某个地方设置了一个断点是 Dotclear 的后台):
(source: pascal-martin.fr)
(来源:pascal-martin.fr)
(In theory, clicking on the image should get you to a bigger version)
(理论上,点击图片应该会让你看到一个更大的版本)
The icons on top of the windows will allow you to do stuff like :
窗口顶部的图标将允许您执行以下操作:
- step by step
- step in / out of functions / methods
- 一步步
- 步入/退出函数/方法
And you can also
你也可以
- see the content of variables (top right of the screenshot)
- have a stack trace showing where you are (top left of the screen shot)
- of course, see were you are in the code (bottom)
- 查看变量的内容(屏幕截图的右上角)
- 有一个堆栈跟踪显示您的位置(屏幕截图的左上角)
- 当然,看看你是否在代码中(底部)
I've also heard that Eclipse PDT can use the Zend Debugger extension instead of Xdebug ; but I've never tried this one.
我还听说 Eclipse PDT 可以使用 Zend Debugger 扩展而不是 Xdebug ;但我从来没有试过这个。
回答by Chio Trujillo
回答by Anuj Dubey
You Can add this code in php.in file for enabling debugger.
您可以在 php.in 文件中添加此代码以启用调试器。
[XDebug]
zend_extension = "D:\opt\lampp\php\ext\php_xdebug.dll"
xdebug.remote_enable=On
xdebug.remote_autostart=On
xdebug.remote_handler=dbgp
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_mode=req