前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >PHP 性能监控:Tideways、xhprof 和 xhgui 打造 PHP 非侵入式监控平台

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

作者头像
猿哥
发布2019-07-01 16:58:31
1.6K0
发布2019-07-01 16:58:31
举报
文章被收录于专栏:Web技术布道师Web技术布道师

环境准备

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

  • 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 配置文件

<?php
return array(
     ...
    'extension' => '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://segmentfault.com/a/1190000019508358

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-06-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 PHP技术大全 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 环境准备
  • 安装 PHP mongodb 扩展
  • 安装 PHP tideaways 扩展
  • 安装 xhgui-branch(xhgui 的汉化版)
  • 启动 mongodb 并设置 xhgui 索引,命令如下:
  • xhgui 本地虚拟主机配置参考
    • 或者也可以在修改 PHP 配置文件,告诉 PHP 程序在执行前要调用的服务
    • 参考链接
    相关产品与服务
    轻量应用服务器
    轻量应用服务器(TencentCloud Lighthouse)是新一代开箱即用、面向轻量应用场景的云服务器产品,助力中小企业和开发者便捷高效的在云端构建网站、Web应用、小程序/小游戏、游戏服、电商应用、云盘/图床和开发测试环境,相比普通云服务器更加简单易用且更贴近应用,以套餐形式整体售卖云资源并提供高带宽流量包,将热门开源软件打包实现一键构建应用,提供极简上云体验。
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档