最近分析调试一个系统的性能,希望用xdebug 辅助一下,但没想到这个东东不像一般的开源系统在window下安装那顺利,过程不是一波三折,根本就是一波三折(折磨的折)。
简单说一下,我的系统环境,
OS:windows xp sp3 英文版本;
Web server: nginx 0.7.65
php: 5.2.17(VC6 thread safe)
在xdbug.org上下载了php_xdebug-2.1.0-5.2-vc6.dll,php.ini也修改了,phpinfo 一看啥都没有;网上查了很多资料,也尝试了很多配置,如最常见的。
[Xdebug]
//zend_extension="your path/php/ext/php_xdebug.dll" <----只有php5.3 以后才这样用;
//extension="your path/php/ext/php_xdebug.dll" <---- 根本不能这样用
zend_extension_ts="your path/php/ext/php_xdebug.dll"
xdebug.default_enable = On
xdebug.collect_params = 4
xdebug.remote_host = 127.0.0.1
xdebug.remote_port = 9000
xdebug.remote_handler = dbgp
xdebug.auto_trace = On
xdebug.show_exception_trace = On
xdebug.remote_autostart = On
xdebug.remote_enable = On
xdebug.collect_vars = On
xdebug.collect_return = On
xdebug.collect_params = On
xdebug.var_display_max_depth = 10
xdebug.remote_req = req
xdebug.profiler_enable = 0
网上,很多人不知道是不是只是转载,不做验证测试(或许我小人了),感觉都是看上去都是一样的文章,很多连错字都一样,根本就是以讹传讹。不过,看了很多,也多少任我提炼一点有用的信息;
后来终于让我找到问题所在了。笨办法,一行行测试配置项,发现remote_port =9000,导致php无法正常加载xdebug模块,修改端口后,终于在phpinfo信息中看到传说中xdebug;
我的最终配置如下(仅作参考,关于xdebug 的详细配置,请参看xdebug的文档):
[Xdebug]
;load xdebug extension
zend_extension_ts = D:/app/PHP/ext/php_xdebug-2.1.0-5.2-vc6.dll
;是否开启自动跟踪
xdebug.auto_trace = On
;是否开启异常跟踪
xdebug.show_exception_trace = On
;是否开启远程调试自动启动
xdebug.remote_autostart = Off
;是否开启远程调试
xdebug.remote_enable = On
;允许调试的客户端IP
xdebug.remote_host=192.168.0.101
;远程调试的端口(默认9000)
;xdebug.remote_port=9001
;调试插件dbgp
xdebug.remote_handler=dbgp
;是否收集变量
xdebug.collect_vars = On
;是否收集返回值
xdebug.collect_return = On
;是否收集参数
xdebug.collect_params = On
;跟踪输出路径
xdebug.trace_output_dir="e:/temp/xdebug"
;是否开启调试内容
xdebug.profiler_enable=On
;调试输出路径
xdebug.profiler_output_dir="e:/temp/xdebug"
以为,这下真的可以用php做分析了,高兴早了,故意搞了几个大陷阱,但是就没看到xdbug那个花花颜色的报错信息,百思不得其解;又放下了几天,直到今天,才忽然想起php.ini中错误信息开关display_errors 上次关闭了,切记,切记,如果要使用Xdebug模块,那么必须修改php.ini中的错误输出。
打开php.ini文件,找到display_errors = Off,改为display_errors = on
经过今天折腾,才基本用上xdebug,用xdebug做新能分析,一定不要忘了WinCacheGrind (同类的有webgrind and KCachegrind--kde下很强大)。