`
xiaoshenge
  • 浏览: 166809 次
  • 性别: Icon_minigender_1
  • 来自: 十堰
社区版块
存档分类
最新评论

PHP之Xdebug,VLD,xhprof

 
阅读更多

 

xdebug:

 

以前听说Xdebug,从别人那里cope了一个dll过来用,发现没起作用。今天发现是php的版本与dll不对应导致的,还好xdebug官网有安装指南。

 

首先到http://xdebug.org/find-binary.php,把你的phpinfo的hml放到form里面,让他们来给你找xdebug对应的dll,然后安装他们的下载安装指南来,就ok了

 

VLD

全名是Vulcan Logic Disassembler,可以用来检测PHP脚本的执行情况。

安装VLD:

wget http://pecl.php.net/get/vld
tar zxvf vld-0.10.1.tgz
cd vld-0.10.1
phpize
./configure
make install

 

编辑php.ini文件激活vld扩展:

extension=vld.so

别忘了重启Apache。

 

问题出现了:在phpinfo中看到vld已经启用,但是执行php -dvld.active=1 a.php没有看到想看到的调试信息。

 

最后在reeze.xia#gmail.com 帮助下解决了:

 

phpinfo是运行在web服务器下看到的把,需要确认下在cli环境下是否加载这个扩展了。


$ php -m 看看是否有vld
如果没有可以通过
$ php -i | grep ini 看看cli模式指向的php.ini文件,如果没有加上,在ini里激活扩展应该就好了。

 

http://derickrethans.nl/more-source-analysis-with-vld.html

http://hi.baidu.com/thinkinginlamp/blog/item/62802f2e4b5edc584fc226a4.html

 

xhprof

 

http://hi.baidu.com/thinkinginlamp/blog/item/f4bd08fa1a03ba9e59ee90fd.html

安装XHProf:

wget http://pecl.php.net/get/xhprof-0.9.2.tgz
tar zxf xhprof-0.9.2.tgz
cd xhprof-0.9.2
cp -r xhprof_html xhprof_lib 
<directory_for_htdocs>
cd extension
phpize
./configure
make
make install


编辑php.ini:

[xhprof]
extension=xhprof.so
;
; directory used by default implementation of the iXHProfRuns
; interface (namely, the XHProfRuns_Default class) for storing
; XHProf runs.
;
xhprof.output_dir=<directory_for_storing_xhprof_runs>


重启服务让修改生效,现在就可以使用XHProf了,不过为了显示效果更炫,最好继续安装Graphviz。

安装Graphviz:

wget http://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.24.0.tar.gz
tar zxf graphviz-2.24.0.tar.gz
cd graphviz-2.24.0
./configure
make
make install


安装完成后,会生成/usr/local/bin/dot文件,你应该确保路径在PATH环境变量里,以便XHProf能找到它。

使用XHProf:

<?php
xhprof_enable
(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);

for (
$i = 0; $i <= 1000; $i++) {
$a = $i * $i;
}

$xhprof_data = xhprof_disable();

$XHPROF_ROOT = "/tools/xhprof/";
include_once
$XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
include_once
$XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";

$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_testing");

echo
"http://localhost/xhprof/xhprof_html/index.php?run={$run_id}&source=xhprof_testing\n";

?>

可是,当我查看[View Full Callgraph]的时候,却提示如下:Error: either we can not find profile data for run_id 4d7f0bd99a12f or the threshold 0.01 is too small or you do not have ‘dot’ image generation utility installed.

 

结果发了很多邮件请教,原因是png没有,谢谢cfc4nphp#gmail.com,详见:

 

http://www.cnxct.com/you-do-not-have-dot-image-generation-utility-installed/

 

编译了libpng源码,再次编译一下Graphviz当打开[View Full Callgraph]的时候,果然是性感的资源占用统计图了。

1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics