linux builds php performance analysis tool

Posted by jalapena on Sat, 11 Apr 2020 17:27:35 +0200

First on the renderings:

Installation environment


php extension


Install MongoDB3

By default, MongoDB2 is installed in my environment yum. xhgui requires version 3 or above.

Create a yum source for MongoDB3

vim /etc/yum.repos.d/mongodb-org-3.4.repo

The contents of the document are:

name=MongoDB Repository


yum install -y mongodb-org

Bad network time may be a little longer

Start MongoDB

service mongod start

Add index

$ 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 } )

If you need to adjust the default port or permissions, search by yourself.

Install xgui Chinese version project

Project address:

Download project code

git clone

composer installation

cd xhgui-branch
composer install

directory right

chmod -R 777 cache

nginx configuration

Configure the virtual host for the xhgui project. The following is my configuration for reference only:

server {
        listen       80;
        root    /your/project/path/xhgui-branch/webroot;
        index index.html index.php;
        rewrite_log on;
        location / {
               try_files $uri $uri/ /index.php?$query_string;

        location ~ [^/]\.php(/|$)
                try_files $uri =404;
                fastcgi_index index.php;
                include fastcgi.conf;

        access_log  /log/path/php_monitor-access.log  access;
        error_log  /log/path/php_monitor-error.log  error;

Edit profile

vim /your/project/path/xhgui-branch/config/config.default.php

Adjust the following:

'extension' => 'tideways_xhprof',
'profiler.enable' => function() {
        if($_SERVER['SERVER_NAME'] == ''){
                // 100% sampling, default is 1%
                return rand(1, 100) === 42;
                return False;

mongodb connection information is filled in according to your own situation.

Configure items to be monitored

Adjust the nginx configuration of the project to be monitored, and add the following configuration:

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

Restart nginx

nginx -s reload

For the first visit, there may be no data temporarily due to the sampling frequency problem, so the sampling frequency can be temporarily increased.

Topics: PHP MongoDB Nginx yum