php xhprof使用

发布时间:2019-08-07 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php xhprof使用脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

xhprof php性能分析

1.clone xhprof 此版本为github第三方扩展 (php官房不支持 php 7)

https://github.com/longxinH/xhprof

2.extension 目录为扩展源码安状扩展即可

phpize && ./configure && make && make install

3.编辑php.ini 启用xhprof扩展

[xhprof]
extension = xhprof.so
xhprof.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 在第一步git clone 后的文件夹里面 
        include '/mnt/d/www/xhprof/xhprof_lib/utils/xhprof_lib.php';
        include '/mnt/d/www/xhprof/xhprof_lib/utils/xhprof_runs.php';
        $objXhprofRun = new XHProfRuns_Default();
        $objXhprofRun->save_run($data, "table"); //生成数据文件后缀
    });

5.nginx 或者 apache 创建 网占目录(apache为例)

<VirtualHost *:80>
    ServerName xhprof.com
    ## xhprof/xhprof_html 在第一步git clone 后的文件夹里面
    DocumentRoot "/mnt/d/www/xhprof/xhprof_html"
    DirectoryIndex index.html index.php index.html
    <Directory "/mnt/d/www/xhprof/xhprof_html">
         Options Indexes FollowSymLinks
         AllowOverride All
         Require all granted
    </Directory>
 </VirtualHost>

6.访问http://xhprof.com/ (上面虚拟主机配置的 本地域名需要host )显示每次程序运行生成的性能分析数据文件 点击可以打 开

php xhprof使用

php xhprof使用

7.如果想要查看性能图点击 view full callgraph (服务器需要安装 graphviz 库)

ubuntu 安装方法 (pro apt-get install graphviz)

8.显示效果图

php xhprof使用

脚本宝典总结

以上是脚本宝典为你收集整理的php xhprof使用全部内容,希望文章能够帮你解决php xhprof使用所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: