安装扩展
该 xhprof扩展版本是从 http://github.com/longxinH/xhprof 获取的(第三方的一个库,官方版本不支持php7)
下载并编译xhprof扩展
在web的html目录下操作:
git clone http://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
添加测试代码
?phpxhprof_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
实际演示代码
?phpfunction test1(){for($i=0;$i $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 !
相关推荐:
LAMP、LNMP和LNAMP的区别和安装
使用Wamp搭建Php本地开发环境以及HBuilder调试的方法
以上就是PHP 7.1安装xhprof进行性能分析的介绍的详细内容,PHP教程
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。
新闻热点
疑难解答