php能单步调试,PHP 的单步调试

想着使用 Xdebug 来搞 php 的单步执行,教程看的这里,http://blog.csdn.net/Eric6/art…,有一点需要小注意的是,需要在 IDE 中建立的项目的文件才能调试,在外面拖进去编辑的文件是不能调试的,这点让我瞎忙活了很久。

但是上面的搭配有一个很大的问题,就是需要从 IDE 内部来发起,我想要的是,在 IDE 上下断点,从浏览器发起,于是就又继续折腾,看到这篇,http://hi.baidu.com/specialbri… ,唉,顿时觉得好好的一个轻巧的 PHP,被 Zend 这些个大块头软件搞得好臃肿的感觉

另外,zend optimizer 已经是不支持 php 5.3 的了,改成了 Zend Guard Loader ,在这里,http://www.zend.com/en/product…,使用的话,看这里,http://www.4wei.cn/archives/10…,但是依然报错,

Fatal error: Incompatible file format: The encoded file has format major ID 1, whereas the Loader expects 4 in C:Program FilesApache Software FoundationApache2.2htdocsZendStudioServerstudioindex.php on line 0

最后 google 到这里,http://forums.kayako.com/threa…,于是看起来无解,现在就是 xdebug 单步。。

===================================================

2012-08-18 09:56:55 update 事实证明, xdebug 也是可以从浏览器发起的,不得不感叹,xdebug 实在强大,终于解决,记录一下步骤,首先,下载安装 xdebug,然后配置 php.ini 的时候需要注意,不要配成类似 ;extension=php_zip.dll 的形式,不然 phpinfo 页面会报错,而是要配成 zend_extension = “C:/php/php-5.3.16/ext/php_xdebug-2.2.1-5.3-vc9-nts.dll” 的形式,然后继续配置其他选项,具体的配置说明强烈推荐官方文档 http://xdebug.org/docs/remote 和 http://xdebug.org/docs/all_set…,最终配成这个样子

[Xdebug]

; 指定xdebug 扩展文件的位置(路径请根据自己的情况做调整)

zend_extension = "C:/php/php-5.3.16/ext/php_xdebug-2.2.1-5.3-vc9-nts.dll"

; 启用xdebug 远程调试

xdebug.remote_enable = 1

;xdebug.remote_autostart=1

xdebug.remote_log="C:/php/xdebug/remote"

xdebug.collect_params=4

xdebug.collect_return=on

xdebug.show_local_vars=on

;xdebug.profiler_enable=on

xdebug.profiler_output_dir="C:/php/xdebug/profile"

;xdebug.auto_trace=on

xdebug.trace_output_dir="C:/php/xdebug/trace"

那个 auto_start 可以按需打开,然后配置 IDE,http://webcache.googleusercont…:rikugun.iteye.com/blog/254512+… ,这里也有提到怎么配置远程的问题,但是跟着做依然不成功,最后找到这里,http://bogdan-albei.blogspot.c…,

Now the tricky part, Eclipse has to be configured to accept debugging sessions from XDebug. Follow the steps below:

Open your project in Eclipse PDT

In the main menu select Project->Properties

On the left side of the window select “PHP Debug” and then click on “Configure Workspace Settings”

On the “PHP Debugger” dropdown select Xdebug and click “Apply”

Click “Configure” to the right of Xdebug in the same window.

Select Xdebug and click “Configure”.

On the “Accept remote session(JIT)” select “any” and click “OK”. This is extremely important and this is where most people get stuck.

That’s it, Eclipse is now configured, now all we need is to be able to be in control of our debugging sessions. For this we will need to install a Firefox extension called “easy Xdebug”(yes Firefox, you’re not developing PHP in IE are you?).

重点就在那个 Accept remote session ,打开之后,就能够从浏览器发起一个请求,转入 IDE 的调试界面了。

而他的工作原理其实是这样的,我们把浏览器所在的机子叫做 local,把跑着 php 脚本的机子叫做 server 的话,xdebug 在 server 上,当我们从浏览器发起一个请求后,到达 server,xdebug 把这个请求拦截下来,然后转入单步运行状态,然后连接回 IDE 所在的机子上的 9000 端口,IDE 则一直监听在 9000,一旦得到信号,就转入 debug 页面,从而完成一个调试过程

除了 auto_start,还有另外一种方式,官方文档说,

HTTP Debug Sessions

Xdebug contains functionality to keep track of a debug session when started through a browser: cookies. This works like this:

When the URL variable XDEBUG_SESSION_START=name is appended to an URL Xdebug emits a cookie with the name “XDEBUG_SESSION” and as value the value of the XDEBUG_SESSION_START URL parameter. The expiry of the cookie is one hour. The DBGp protocol also passes this same value to the init packet when connecting to the debugclient in the “idekey” attribute.

When there is a GET (or POST) variable XDEBUG_SESSION_START or the XDEBUG_SESSION cookie is set, Xdebug will try to connect to a debugclient.

To stop a debug session (and to destroy the cookie) simply add the URL parameterXDEBUG_SESSION_STOP. Xdebug will then no longer try to make a connection to the debugclient.

===========================================================

2012-08-18 15:00:49 update 使用这个 debug 有一个问题,在于会出现 unexpected termination of script, debugging ended 的提示,google 一下看到这里也有人在吐槽,http://stackoverflow.com/quest…,虽然里面有人说换个低版本可以解决,但是我换了还是不行,估计真的是个 bug

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值