当前位置:编程学习 > > 正文

php编写程序使用方法(php xhprof使用实例详解)

时间:2022-03-30 00:45:21类别:编程学习

php编写程序使用方法

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扩展

  • ?
  • 1
  • 2
  • 3
  • [xhprof]
  • extension = xhprof.so
  • xhprof.output_dir = /tmp/xhprof ;性能分析数据文件存放位置 需要php用户有可写可读权限
  • 4.对项目入口文件添加代码

  • ?
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 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为例)

  • ?
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • <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编写程序使用方法(php xhprof使用实例详解)

    php编写程序使用方法(php xhprof使用实例详解)

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

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

    8.显示效果图

    php编写程序使用方法(php xhprof使用实例详解)

    总结

    以上所述是小编给大家介绍的php xhprof使用实例详解 ,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对开心学习网网站的支持!

    如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

    原文链接:https://segmentfault.com/a/1190000018856380

    标签:
    上一篇下一篇

    猜您喜欢

    热门推荐