PHP性能分析工具xhprof安装及使用
分类:PHP, 发布于 2018-03-29 07:37:18 浏览(717)
对于本地开发环境来说,进行性能分析xdebug是够用了,但如果是线上环境的话,xdebug消耗较大,配置也不够灵活,因此线上环境建议使用xhprof进行PHP性能追踪及分析。
1、安装xhprof
git clone https://github.com/longxinH/xhprof cd xhprof/extension/ phpize ./configure make && make install
然后在/etc/php.d/中加入xhprof.ini,内容为extension=xhprof.so
重启php-fpm
为了更直观,可以安装图片组件
yum install graphviz
至此xhprof扩展安装完成,下面是使用过程:
在文件入口输入启用方法
xhprof_enable();
在结束位置添加
$xhprof_data = xhprof_disable(); include_once $_SERVER['DOCUMENT_ROOT']."/xhprof_lib.php"; include_once $_SERVER['DOCUMENT_ROOT']."/xhprof_runs.php"; $xhprof_runs = new \XHProfRuns_Default(); $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo"); die("http://192.168.3.5/xhprof/xhprof_html/index.php?run=$run_id&source=xhprof_foo");
根据你的文件目录配置,点击以上地址查看分析结果
以下测试md5和sha1的结果: