下载xhprof
http://pecl.php.net/package/xhprof
解压缩
tar ***.tgz
安装:
pecl install xhprof....tgz
配置
[xhprof]
extension=xhprof.so
xhprof.output_dir=/work/code/xhprof
使用:
xhprof_enable();
//你需要分析的代码
$xhprof_data = xhprof_disable();
include_once ROOT_PATH.'/xhprof_lib/utils/xhprof_lib.php';
include_once ROOT_PATH . '/xhprof_lib/utils/xhprof_runs.php';
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_test");
//将run_id保存起来或者随代码一起输出
查看:
xhprof_html 在tgz包中
访问$host_url/xhprof_html/index.php?run=58d3b28b521f6&source=xhprof_test
来查看结果
或者:
进入xhprof.tgz解压目录
cd xhprof-2.2.0/xhprof_html
使用php原生服务器 执行
$ php -S 0.0.0.0:8000
浏览器打开: http://192.168.56.40:8000/
图形化结果
点击[View Full Callgraph]
可以看图形化结果
报错
failed to execute cmd:" dot -Tpng". stderr:sh: dot:command not found。
//解决方案
yum install graphviz
参考