linux builds php performance analysis tool

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

First on the renderings:


Installation environment

Centos,php7,MongoDB3,nginx

php extension

mongodb: http://pecl.php.net/package/mongodb
tideways_xhprof: https://github.com/tideways/php-xhprof-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:

[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc

install

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:

https://github.com/laynefyc/xhgui-branch

Download project code

git clone https://github.com/laynefyc/xhgui-branch.git

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;
        server_name php.monitor.com;
        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_pass  127.0.0.1:9000;
                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'] == 'your.project.domain.com'){
                // 100% sampling, default is 1%
                return rand(1, 100) === 42;
        }else{
                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