Tideways, xhprof and xhgui build PHP non-invasive monitoring platform

Recommended Reading

Preparing the Environment

Before installing ensure that the following software has been installed correctly

  • PHP
  • Nginx
  • Mongodb

Install PHP mongodb extensions

$ sudo pecl install mongodb
复制代码

PHP configuration file to add

[mongodb]
extension=mongodb.so
复制代码

Install PHP tideaways extensions

Conventional compile and install

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

PHP configuration file to add

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

Installation xhgui-branch (xhgui finished version)

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

Modify xhgui-branch configuration file

<?php
return array(
 	...
    'extension' => 'tideways_xhprof',
 	...
    'save.handler' => 'mongodb',
    'db.host' => 'mongodb://127.0.0.1:27017',
    'db.db' => 'xhprof',
 	...
);
复制代码

Start mongodb and set xhgui index, the command is as follows:

$ 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 local virtual host configuration reference

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;
    }
}
复制代码

Be set up for the site to be analyzed, nginx configuration to be analyzed directly on the site, add the following entry, and then enable the configuration on it.

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

Reference configuration

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";
}
复制代码

Or you can modify the PHP configuration file that tells PHP service before executing the program to be called

; Automatically add files before PHP document.
; http://php.net/auto-prepend-file
auto_prepend_file = "/path/wwwroot/xhgui-branch/external/header.php"
复制代码

Reference links

Reproduced in: https: //juejin.im/post/5d0843006fb9a07ee9587189

Guess you like

Origin blog.csdn.net/weixin_34179968/article/details/93165629