安装扩展
该 xhprof扩展版本是从 https://github.com/longxinH/xhprof 获取的(第三方的一个库,官方版本不支持php7)
下载并编译xhprof扩展
在web的html目录下操作:
git clone https://github.com/longxinH/xhprof
编译扩展
cd xhprof/extension/phpize ./configure makemake install
修改php.ini配置
[xhprof] extension=xhprof.so; xhprof.output_dir=/tmp/xhprof
其中 xhprof.output_dir 是 xhprof 的输出目录,每次执行 xhprof 的 save_run 方法时都会生成一个 run_id.project_name.xhprof 文件。这个目录在哪里并不重要。注意此路径的权限要可读写!!否则文件无法生成成功
重启 php-fpm
sudo service php7.1-fpm restart
添加测试代码
<?php xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);// 要检查性能的代码 $xhprof_data = xhprof_disable(); include_once '/var/www/html/xhprof/xhprof_lib/utils/xhprof_lib.php'; include_once '/var/www/html/xhprof/xhprof_lib/utils/xhprof_runs.php'; $xhprof_runs = new \XHProfRuns_Default(); $run_id = $xhprof_runs->save_run($xhprof_data, 'your_project');
测试代码中要引入xhprof_lib.php和xhprof_runs.php两个文件
查看生成报告
需要访问:xhprof/xhprof_html/index.php文件查看:
http://localhost/xhprof/xhprof_html/index.php?run=5b35d3dfa8c29&source=your_project
run后的参数为$run_id,source参数为your_project配置的名字
如果图表生成错误,需要安装插件:
sudo apt-get install graphviz
实际演示代码
<?php function test1(){ for($i=0;$i<10;$i++){ echo 'aaa'.$i.'<br>'; } }// start profilingxhprof_enable(); test1(); // stop profiler $xhprof_data = xhprof_disable(); // display raw xhprof data for the profiler runprint_r($xhprof_data); include_once "xhprof_lib.php";include_once "xhprof_runs.php"; // save raw data for this profiler run using default // implementation of iXHProfRuns. $xhprof_runs = new XHProfRuns_Default(); // save the run under a namespace "xhprof_test" $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_test");echo "---------------\n". "Assuming you have set up the http based UI for \n". "XHProf at some address, you can view run at \n". "http://<xhprof-ui-address>/index.php?run=$run_id&source=xhprof_test\n". "---------------\n";
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
使用Wamp搭建Php本地开发环境以及HBuilder调试的方法
以上就是PHP 7.1安装xhprof进行性能分析的介绍的详细内容,更多请关注php中文网其它相关文章!
![php中文网最新课程二维码](/static/images/article_wechat2021.jpg?1111)
声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理
- 上一篇:PHP判断链接是否有效 的方法
- 下一篇:php实现称砝码的方法介绍
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论