当前位置: 首页 > 后端技术 > PHP

phpxhprof使用

时间:2023-03-29 13:56:41 PHP

xhprofphp性能分析1.clonexhprof这个版本是github的第三方扩展(php官房不支持php7)https://github.com/longxinH/xhprof2.extension目录是扩展源码,以及扩展可以是phpize&&./configure&&make&&makeinstall3.编辑php.ini以启用xhprof扩展[xhprof]extension=xhprof.soxhprof.output_dir=/tmp/xhprof;性能分析数据文件存放位置需要php用户有可写可读权限4.为项目入口文件添加代码xhprof_enable(XHPROF_FLAGS_NO_BUILTINS+XHPROF_FLAGS_CPU+XHPROF_FLAGS_MEMORY);register_shutdown_function(function(){$data=xhprof_disable();//xhprof_lib在第一步gitclone/utils/xhprof_lib.php之后的文件夹中包含'/mnt/d/www/xhprof/xhprof';include'/mnt/d/www/xhprof/xhprof_lib/utils/xhprof_runs.php';$objXhprofRun=newXHProfRuns_Default();$objXhprofRun->save_run($data,"table");//生成数据文件后缀});5.nginx或apache创建在线记账目录(以apache为例)ServerNamexhprof.com##xhprof/xhprof_html第一步gitclone后文件夹中的DocumentRoot"/mnt/d/www/xhprof/xhprof_html"DirectoryIndexindex.htmlindex.phpindex.htmlOptionsIndexesFollowSymLinksAllowOverrideAllRequireallgranted6.访问http://xhprof.com/(上面虚拟主机配置的本地域名需要host)显示程序每次运行时产生的性能分析数据文件,点击打开7.如果要查看性能图,点击viewfullcallgraph(服务器需要安装graphviz库)ubuntu安装方法(proapt-getinstallgraphviz)8.显示效果图