环境准备

安装之前确保已经正确安装了以下软件

  • PHP
  • Nginx
  • Mongodb

安装 PHP mongodb 扩展

$ sudo pecl install mongodb

PHP 配置文件中添加

[mongodb]extension=mongodb.so

安装 PHP tideaways 扩展

常规编译安装

$ git clone https://github.com/tideways/php-xhprof-extension.git$ cd /path/php-xhprof-extension$ phpize$ ./configure$ make$ sudo make install

PHP 配置文件中添加

[tideways]extension=tideways_xhprof.so; 不需要自动加载,在程序中控制就行tideways.auto_prepend_library=0; 频率设置为100,在程序调用时可以修改tideways.sample_rate=100

安装 xhgui-branch(xhgui 的汉化版)

$ git clone https://github.com/laynefyc/xhgui-branch.git$ cd xhgui-branch$ php install.php

修改 xhgui-branch 配置文件

<?phpreturn array(     ...    'extension' => 'tideways_xhprof',     ...    'save.handler' => 'mongodb',    'db.host' => 'mongodb://127.0.0.1:27017',    'db.db' => 'xhprof',     ...);

启动 mongodb 并设置 xhgui 索引,命令如下:

$ mongo> use xhprof> db.results.ensureIndex( { 'meta.SERVER.REQUEST_TIME' : -1 } )> db.results.ensureIndex( { 'profile.main().wt' : -1 } )> db.results.ensureIndex( { 'profile.main().mu' : -1 } )> db.results.ensureIndex( { 'profile.main().cpu' : -1 } )> db.results.ensureIndex( { 'meta.url' : 1 } )

xhgui 本地虚拟主机配置参考

server {    listen       80;    server_name  xhgui.test;    root         /Users/yaozm/Documents/wwwroot/xhgui-branch/webroot;    # access_log  /usr/local/var/log/nginx/access.log;    error_log  /usr/local/var/log/nginx/error.log;    location / {        try_files $uri $uri/ /index.php?$query_string;        index  index.php index.html index.htm;    }}

针对要分析的站点进行设置,直接在要分析站点的 nginx 配置中增加以下项,然后使配置生效就可以了。

$ fastcgi_param PHP_VALUE "auto_prepend_file=/path/xhgui-branch/external/header.php";

参考配置

server {    listen       80;    server_name  laravel.test;    root         /Users/yaozm/Documents/wwwroot/laravel/public;    # access_log  /usr/local/var/log/nginx/access.log;    error_log  /usr/local/var/log/nginx/error.log;    location / {        try_files $uri $uri/ /index.php?$query_string;        index  index.php index.html index.htm;    }     # 添加 PHP_VALUE,告诉 PHP 程序在执行前要调用的服务    fastcgi_param PHP_VALUE "auto_prepend_file=/path/wwwroot/xhgui-branch/external/header.php";}

或者也可以在修改 PHP 配置文件,告诉 PHP 程序在执行前要调用的服务

; Automatically add files before PHP document.; http://php.net/auto-prepend-fileauto_prepend_file = "/path/wwwroot/xhgui-branch/external/header.php"

更多PHP相关技术文章,请访问PHP教程栏目进行学习!

更多相关文章

  1. 使用 phpdbg 来调试php程序
  2. 使用PHP自建稳定可靠的守护程序
  3. php程序员经常忽略的冷门知识点
  4. PHP 编写基本的 Socket 程序
  5. 解决PHP中Web程序中shell_exec()执行Shell脚本不成功问题
  6. 浅谈PHP程序员如何修炼?
  7. 程序员的快乐就是这么朴素无华且枯燥
  8. 做一个诚信的程序员有多难?
  9. 过年了,给亲朋好友解释「啥是程序员」

随机推荐

  1. 使用wdcp完成网站搭建
  2. linux忘记root密码的两种修改方法
  3. Linux Socket编程(不限Linux)
  4. Git - 将Github仓库与本地仓库同步?
  5. 新人求助:tensorflow官方文档里构建第一个
  6. Linux 驱动开发之内核模块开发 (三)—— 模
  7. 文本处理小工具SED用法
  8. Linux学习之文件系统权限及表示
  9. Linux daemon进程的应用、实现和原理
  10. Linux下Mycat安装配置