windows環境配置xhgui監控thinkphp

環境說明

web環境phpEnv

php版本7.2

 thinkphp版本6.0.2

安裝xhprof擴展

windows tideways-xhprof 擴展

  1. 選擇對應版本擴展
  2. 解壓至php/ext目錄
  3. 配置php.ini增加引入擴展,重啓服務生效

extension = tideways_xhprof.dll

安裝xhgui中文版

xhgui中文版

git clone https://github.com/laynefyc/xhgui-branch xhgui-cn
cd xhgui-cn
php install.php
composer update

composer.phar下載比較慢,可以自己複製本地的composer.phar至 xhgui-cn目錄,然後再執行php install.php

mongo連接配置

編輯config/config.default.php

// 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',
'db.host'              => 'mongodb://192.168.102.137:27017',
'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(
    'username' => '賬號',
    'password' => '密碼',
),

設置擴展爲tideways_xhprof

    /*
     * support extension: uprofiler, tideways_xhprof, tideways, xhprof
     * default: xhprof
     */
    'extension'            => 'tideways_xhprof',

添加站點至xhgui-cn/webroot 

訪問www.xhgui.com,看到如下界面說明xhgui部署完成

引入監控

  • 入口文件引入
  • // [ 應用入口文件 ]
    namespace think;
    
    require __DIR__ . '/../vendor/autoload.php';
    
    require 'd:/www/xhgui-cn/external/header.php';
    
    // 執行HTTP應用並響應
    $http = (new App())->http;
    
    $response = $http->run();
    
    $response->send();
    
    $http->end($response);

     

  • BaseController引入(推薦)
  •     /**
         * 構造方法
         * @access public
         * @param  App  $app  應用對象
         */
        public function __construct(App $app)
        {
            $this->app = $app;
            $xhprof    = 'd:/www/xhgui-cn/external/header.php';
            if ($this->app->isDebug() && file_exists($xhprof)) {
                require $xhprof;
            }
            $this->request = $this->app->request;
    
            // 控制器初始化
            $this->initialize();
        }

    在debug模式下啓用監控

  • 訪問被監控的站點後,再查看www.xhgui.com就可以看到監控的信息了

參考鏈接

https://blog.it2048.cn/article-tideways-xhgui/

https://blog.csdn.net/weixin_37281289/article/details/96591978?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-5.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-5.nonecase

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章