资讯专栏INFORMATION COLUMN

Tideways、xhprof 和 xhgui 打造 PHP 非侵入式监控平台

shevy / 3655人阅读

摘要:参考配置添加,告诉程序在执行前要调用的服务或者也可以在修改配置文件,告诉程序在执行前要调用的服务参考链接

推荐阅读

Tideways、xhprof 和 xhgui 打造 PHP 非侵入式监控平台

超全的设计模式简介(45种)

design-patterns-for-humans 中文版

MongoDB 资源、库、工具、应用程序精选列表中文版

有哪些鲜为人知,但是很有意思的网站?

一份攻城狮笔记

每天搜集 Github 上优秀的项目

一些有趣的民间故事

超好用的谷歌浏览器、Sublime Text、Phpstorm、油猴插件合集

环境准备

安装之前确保已经正确安装了以下软件

PHP

Nginx

Mongodb

安装 PHP mongodb 扩展
$ sudo pecl install mongodb

PHP 配置文件中添加

[mongodb]
extension=mongodb.so
安装 PHP tideaways 扩展

常规编译安装

$ git clone https://github.com/tideways/php-xhprof-extension.git
$ cd /path/php-xhprof-extension
$ phpize
$ ./configure
$ make
$ sudo make install

PHP 配置文件中添加

[tideways]
extension=tideways_xhprof.so
; 不需要自动加载,在程序中控制就行
tideways.auto_prepend_library=0
; 频率设置为100,在程序调用时可以修改
tideways.sample_rate=100
安装 xhgui-branch(xhgui 的汉化版)
$ git clone https://github.com/laynefyc/xhgui-branch.git
$ cd xhgui-branch
$ php install.php

修改 xhgui-branch 配置文件

 "tideways_xhprof",
     ...
    "save.handler" => "mongodb",
    "db.host" => "mongodb://127.0.0.1:27017",
    "db.db" => "xhprof",
     ...
);
启动 mongodb 并设置 xhgui 索引,命令如下:
$ 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 } )
xhgui 本地虚拟主机配置参考
server {
    listen       80;
    server_name  xhgui.test;
    root         /Users/yaozm/Documents/wwwroot/xhgui-branch/webroot;

    # access_log  /usr/local/var/log/nginx/access.log;
    error_log  /usr/local/var/log/nginx/error.log;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
        index  index.php index.html index.htm;
    }
}
针对要分析的站点进行设置,直接在要分析站点的 nginx 配置中增加以下项,然后使配置生效就可以了。
$ fastcgi_param PHP_VALUE "auto_prepend_file=/path/xhgui-branch/external/header.php";

参考配置

server {
    listen       80;
    server_name  laravel.test;
    root         /Users/yaozm/Documents/wwwroot/laravel/public;

    # access_log  /usr/local/var/log/nginx/access.log;
    error_log  /usr/local/var/log/nginx/error.log;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
        index  index.php index.html index.htm;
    }
     # 添加 PHP_VALUE,告诉 PHP 程序在执行前要调用的服务
    fastcgi_param PHP_VALUE "auto_prepend_file=/path/wwwroot/xhgui-branch/external/header.php";
}
或者也可以在修改 PHP 配置文件,告诉 PHP 程序在执行前要调用的服务
; Automatically add files before PHP document.
; http://php.net/auto-prepend-file
auto_prepend_file = "/path/wwwroot/xhgui-branch/external/header.php"

参考链接

https://github.com/phacility/xhprof

https://github.com/perftools/xhgui

https://github.com/tideways/php-xhprof-extension

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

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

https://zhuanlan.zhihu.com/p/30832165

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/31725.html

相关文章

  • Tidewaysxhprof xhgui 打造 PHP 侵入监控平台

    摘要:参考配置添加,告诉程序在执行前要调用的服务或者也可以在修改配置文件,告诉程序在执行前要调用的服务参考链接 showImg(https://segmentfault.com/img/bVbt7t1?w=2880&h=2608); 推荐阅读 Tideways、xhprof 和 xhgui 打造 PHP 非侵入式监控平台 超全的设计模式简介(45种) design-patterns-for...

    Cympros 评论0 收藏0
  • Docker的LNMP一键安装开发环境 + PHP侵入监控平台xhgui(优化系统性能、定位Bu

    摘要:的一键安装开发环境非侵入式监控平台优化系统性能定位的神器之前在用做本地开发环境,因为没有这些对程序性能追踪及分析的工具,所以索性基于的编排了一套自己使用。 DNMP PLUS dnmp = Docker + Nginx + MySQL + PHP + Redis + MongDB plus = xhgui + xhprof + tideways dnmp-plus = PHPer 的一...

    AlanKeene 评论0 收藏0
  • Docker的LNMP一键安装开发环境 + PHP侵入监控平台xhgui(优化系统性能、定位Bu

    摘要:日志日志是我们用得最多的日志,所以我们单独放在根目录下。会目录映射容器的目录,所以在配置文件中,需要输出的位置,我们需要配置到目录,如日志因为容器中的使用的是用户启动,它无法自行在下的增加日志文件。 DNMP PLUS dnmp = Docker + Nginx + MySQL + PHP + Redis + MongDB plus = xhgui + xhprof + tideway...

    luzhuqun 评论0 收藏0

发表评论

0条评论

shevy

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<