Tideways & Xhgui 性能监控
                    
                    
										# 					PHP					                    
                
                本教程基于php7运行环境进行编写
前言
由于版本迭代速度过快导致各种性能问题未能及时解决,遗留下一堆技术债。目前急需解决接口请求超过运行时间0.8s指标的接口,如果人工一句一句代码去排查,不但要耗费大量时间还会增加异常bug的产生可能性。所以Tideways(非侵入式性能分析工具)就从此诞生。
安装教程
1.安装mongodb拓展
pecl install mongodb2.安装tideways拓展
wget --no-check-certificate https://github.com/tideways/php-xhprof-extension/archive/v4.1.7.tar.gz
tar zxvf v4.1.7.tar.gz
cd php-xhprof-extension-4.1.7
phpize && ./configure && make && make install3.修改php配置文件,增加拓展配置
#php.ini
# mongodb 拓展加载
extension=mongodb.so
# tideways 拓展加载
extension=tideways.so
# tideways 设置不需要自动加载
tideways.auto_prepend_library=04.重启php-fpm
5.下载xhgui可视化工具
git clone https://github.com/yiqiang3344/xhgui-branch.git
cd xhgui-branch && php install6.配置xhgui配置文件
<?php  //config/config.default.php ?>
<?php
/**
 * Default configuration for Xhgui
 */
return array(
    'debug' => false,
    'mode' => 'development',
    /*
     * support extension: uprofiler, tideways_xhprof, tideways, xhprof
     * default: xhprof
     */
    'extension' => 'tideways',
    // Can be either mongodb or file.
    /*
    'save.handler' => 'file',
    'save.handler.filename' => dirname(__DIR__) . '/cache/' . 'xhgui.data.' . microtime(true) . '_' . substr(md5($url), 0, 6),
    */
    'save.handler' => 'mongodb',
    // Needed for file save handler. Beware of file locking. You can adujst this file path
    // to reduce locking problems (eg uniqid, time ...)
    //'save.handler.filename' => __DIR__.'/../data/xhgui_'.date('Ymd').'.dat',
    //mongodb://root:root@192.168.109.139:27017
    'db.host' => 'mongodb链接uri',
    //db name
    'db.db' => 'xhprof',
    // Allows you to pass additional options like replicaSet to MongoClient.
    // 'username', 'password' and 'db' (where the user is added)
    'db.options' => array(),
    'templates.path' => dirname(__DIR__) . '/src/templates',
    'date.format' => 'Y-m-d H:i:s',
    'detail.count' => 6,
    'page.limit' => 25,
    // Profile 1 in 100 requests.
    // You can return true to profile every request.
    'profiler.enable' => function() {
        return true;//rand(1, 100) === 42;
    },
    'profiler.simple_url' => function($url) {
        return preg_replace('/\=\d+/', '', $url);
    },
    'profiler.filter_path' => array(
      //xhgui运行目录,如不配置则会一起监控性能
      //  '/var/www/xhgui-branch/webroot'
    )
);7.配置xhgui nginx配置
# php_monitor.conf
server {
    listen 80;
    server_name php_monitor.dev.cn;
    root /var/www/xhgui-branch/webroot;
    index index.php index.html index.htm;
    location / {
         try_files $uri $uri/ /index.php$is_args$args;
    }
    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass php-upstream;
        fastcgi_index index.php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fixes timeouts
        fastcgi_read_timeout 600;
        include fastcgi_params;
    }
}8.配置需要监听性能目标网站nginx配置
# 目标nginx配置文件
fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/xhgui-branch/external/header.php";使用教程
查看历史请求接口

查看某个接口请求性能情况



查看某个接口火焰图(可高效分析出运行慢原因)

华纳公司合作开户所需材料?电话号码15587291507 微信STS5099
华纳公司合作开户所需材料?电话号码15587291507 微信STS5099
华纳公司合作开户所需材料?电话号码15587291507 微信STS5099
华纳公司合作开户所需材料?电话号码15587291507 微信STS5099
华纳公司合作开户所需材料?电话号码15587291507 微信STS5099
华纳公司合作开户所需材料?电话号码15587291507 微信STS5099
华纳公司合作开户所需材料?电话号码15587291507 微信STS5099
华纳公司合作开户所需材料?电话号码15587291507 微信STS5099
2025年10月新盘 做第一批吃螃蟹的人coinsrore.com
新车新盘 嘎嘎稳 嘎嘎靠谱coinsrore.com
新车首发,新的一年,只带想赚米的人coinsrore.com
新盘 上车集合 留下 我要发发 立马进裙coinsrore.com
做了几十年的项目 我总结了最好的一个盘(纯干货)coinsrore.com
新车上路,只带前10个人coinsrore.com
新盘首开 新盘首开 征召客户!!!coinsrore.com
新项目准备上线,寻找志同道合 的合作伙伴coinsrore.com
新车即将上线 真正的项目,期待你的参与coinsrore.com
新盘新项目,不再等待,现在就是最佳上车机会!coinsrore.com
新盘新盘 这个月刚上新盘 新车第一个吃螃蟹!coinsrore.com
新盘新项目,不再等待,现在就是最佳上车机会!coinsrore.com