Home >Backend Development >PHP Tutorial >PHP performance analysis platform construction

PHP performance analysis platform construction

步履不停
步履不停Original
2019-07-01 15:44:374058browse

PHP performance analysis platform construction

PHP performance analysis platform construction (tideways xhgui nginx php7)

Introduction

Build a PHP performance analysis platform without changing your program Code, use nginx to add a monitoring layer on top of your program (to produce fixed logs), analyze the program information of the log, and perform performance analysis and optimization

1. Install mongodb

Omit 1000 words here, find the document yourself

2. Install mongodb extension

    wget http://pecl.php.net/get/mongodb-1.4.0.tgz
    tar -zxvf mongodb-1.4.0.tgz
    cd mongodb-1.4.0
    phpize
    ./configure --with-php-config=你的php-config路径 我的是在/usr/local/Cellar/php@7.1/7.1.16_1/bin/php-config
    make
    make install

3. Install tideways extension

    git clone https://github.com/tideways/php-profiler-extension.git
    cd php-profiler-extension
    phpize
    ./configure --with-php-config=你的php-config路径
    make 
    make install

4. Modify configuration file

    extension=tideways.so
    tideways.auto_prepend_library=0
    extension=mongodb.so

5. Download the xhgui project

    #https://github.com/perftools/xhgui  (汉化)
    git clone https://github.com/perftools/xhgui.git
    cd xhgui
    php install.php(看下是否有vendor这个目录)
    ##项目配置
    #配置文件:config/default_config.php
    #运行目录:webroot
    #nginx rewrite规则
    #   location / {  
    #       try_files $uri $uri/ /index.php$is_args$query_string;  
    #   }

6. Modify the configuration file

#xhgui 默认是采集1% ,如果是排查问题时还是希望能够100%采集会比较方便。进入xhgui源码目录,修改config/config.default.php文件,
#平时仍然按1%的采样率采样,防止数据增长过快,当想调试时,就在URL中添加debug=1的参数即可。
#在xhgui/config/config.default.php中,找到profiler.enable这里,按如下修改:
#mongo
//采样率
'profiler.enable' => function() {
    // url 中包含debug=1则百分百捕获
    if(!empty($_GET['debug'])){
        return true;
    } else {
        // 1%采样
        return rand(1, 100) === 42;
    }
},
//优化建议:可以给mongo数据表加上索引

7. Use & effect

//在需要的项目中的最开始,引入文件即可
require "/dir/external/header.php";
//操作项目,即可在xhgui平台中查看数据分析性能

The effect is as shown below

PHP performance analysis platform constructionPHP performance analysis platform construction

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

The above is the detailed content of PHP performance analysis platform construction. 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