php安装xhprof性能分析
git clone https://github.com/longxinH/xhprof
安装 xhprof
cd xhprof/extension/ /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config --enable-xhprof
make
make install
出现
Installing shared extensions: /opt/php-7.0.14/lib/php/extensions/no-debug-non-zts-20151012/
代表编译成功
修改 php.ini 文件
在/etc/php.ini中增加如下配置
[xhprof] extension=xhprof.so xhprof.output_dir=/tmp/save_output_dir //该目录自由定义即可,用来保存xhprof生成的源文件
保存好之后,重启php-fpm
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
将相关文件移动到项目中
//切换到下载的 xhprof 目录 cp -r xhprof/xhprof_html 项目根目录/ cp -r xhprof/xhprof_lib 项目根目录/
使用
1 xhprof_enable(); 2 3 //你需要分析的代码 4 5 $xhprof_data = xhprof_disable(); 6 include_once ROOT_PATH.'/xhprof_lib/utils/xhprof_lib.php'; 7 include_once ROOT_PATH . '/xhprof_lib/utils/xhprof_runs.php'; 8 9 $xhprof_runs = new XHProfRuns_Default(); 10 11 $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_test"); 12 //将run_id保存起来或者随代码一起输出
查看数据
访问
根域名/xhpfrof_html/index.php?run=58d3b28b521f6&source=xhprof_test
来查看结果
图形化结果
点击[View Full Callgraph]可以看图形化结果
报错
failed to execute cmd:" dot -Tpng". stderr:sh: dot:command not found。
//解决方案
yum install graphviz
支持原创!!!
作者:躁动的石头
链接:http://www.jianshu.com/p/c420ebe6ce39
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
看活一分钟公众号,持续订阅,更有精赞内容分享

浙公网安备 33010602011771号