Home  >  Article  >  Backend Development  >  Tideways, xhprof and xhgui create a non-intrusive monitoring platform for PHP

Tideways, xhprof and xhgui create a non-intrusive monitoring platform for PHP

步履不停
步履不停Original
2019-06-18 15:23:092495browse

Tideways, xhprof and xhgui create a non-intrusive monitoring platform for PHP

Environment preparation

Before installation, make sure the following software has been installed correctly

  • PHP
  • Nginx
  • Mongodb

Install PHP mongodb extension

$ sudo pecl install mongodb

Add in PHP configuration file

[mongodb]
extension=mongodb.so

Install PHP tideaways extension

General compilation and installation

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

Add to the PHP configuration file

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

Install xhgui-branch (Chinese version of xhgui)

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

Modify the xhgui-branch configuration file

<?php
return array(
     ...
    &#39;extension&#39; => 'tideways_xhprof',
     ...
    'save.handler' => 'mongodb',
    'db.host' => 'mongodb://127.0.0.1:27017',
    'db.db' => 'xhprof',
     ...
);

Start mongodb and Set the 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;
    }
}

Set for the site to be analyzed, add the following items directly to the nginx configuration of the site to be analyzed, and then use Just make sure the configuration takes effect.

$ 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 to tell the PHP program the services to be called before execution

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

For more PHP related technical articles, please Visit the PHP Tutorial column to learn!

The above is the detailed content of Tideways, xhprof and xhgui create a non-intrusive monitoring platform for PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn