环境说明
web环境phpEnv
php版本7.2
thinkphp版本6.0.2
安装xhprof扩展
windows tideways-xhprof 扩展
- 选择对应版本扩展
- 解压至php/ext目录
- 配置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/