1、下载源码包 https://github.com/longxinH/xhprof  (wget https://github.com/longxinH/xhprof/archive/master.zip)    下面截图那个是官网的,已经没有维护了,不行了。

  php----------php安装xhprof扩展和简单使用

2、编译

  php----------php安装xhprof扩展和简单使用

  php----------php安装xhprof扩展和简单使用

3、./configure --with-php-config=/usr/local/php/bin/php-config

  php----------php安装xhprof扩展和简单使用

4、make && make install

  php----------php安装xhprof扩展和简单使用

5、然后在 /etc/php.ini里面增加 extension=xhprof.so  保存退出。完成,执行php -m可以查看一下。

6、将之前下载的扩展包,移动到网站根目录下

  php----------php安装xhprof扩展和简单使用

  然后直接访问 http://192.168.18.160/xhprof/examples/sample.php

  php----------php安装xhprof扩展和简单使用

  拿到红线画的以后,直接访问 http://192.168.18.160/xhprof/xhprof_html/index.php?run=5ac86cc0cec09&source=xhprof_foo

php----------php安装xhprof扩展和简单使用

  然后安装 yum install -y graphviz

  点击箭头指的地方,就可以看到图形界面

  php----------php安装xhprof扩展和简单使用

  红色代表运行时间长的代码块

  http://192.168.18.160/xhprof/xhprof_html/index.php  可以查看历史检测的记录

  php----------php安装xhprof扩展和简单使用

7、正式项目中,在入口文件加入

开头 : xhprof_enable();

结尾:

  $data = xhprof_disable();
  include_once "/usr/local/nginx/html/laravel/public/xhprof/xhprof_lib/utils/xhprof_lib.php";
  include_once "/usr/local/nginx/html/laravel/public/xhprof/xhprof_lib/utils/xhprof_runs.php";
  $aa = new XHProfRuns_Default();
  $aa->save_run($data,"test");

相关文章: