溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

Tideways、xhprof 和 xhgui 如何打造 PHP 非侵入式監(jiān)控平臺(tái)

發(fā)布時(shí)間:2020-07-10 09:50:12 來(lái)源:億速云 閱讀:238 作者:Leah 欄目:編程語(yǔ)言

本篇文章給大家分享的是有關(guān)Tideways、xhprof 和 xhgui 如何打造 PHP 非侵入式監(jiān)控平臺(tái),小編覺(jué)得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話(huà)不多說(shuō),跟著小編一起來(lái)看看吧。

環(huán)境準(zhǔn)備

安裝之前確保已經(jīng)正確安裝了以下軟件

安裝 PHP mongodb 擴(kuò)展

$ sudo pecl install mongodb

PHP 配置文件中添加

[mongodb]
extension=mongodb.so

安裝 PHP tideaways 擴(kuò)展

常規(guī)編譯安裝

$ 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
; 不需要自動(dòng)加載,在程序中控制就行
tideways.auto_prepend_library=0
; 頻率設(shè)置為100,在程序調(diào)用時(shí)可以修改
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',
     ...
);

啟動(dòng) mongodb 并設(shè)置 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 本地虛擬主機(jī)配置參考

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;
    }
}

針對(duì)要分析的站點(diǎn)進(jìn)行設(shè)置,直接在要分析站點(diǎn)的 nginx 配置中增加以下項(xiàng),然后使配置生效就可以了。

$ 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 程序在執(zhí)行前要調(diào)用的服務(wù)
    fastcgi_param PHP_VALUE "auto_prepend_file=/path/wwwroot/xhgui-branch/external/header.php";
}

或者也可以在修改 PHP 配置文件,告訴 PHP 程序在執(zhí)行前要調(diào)用的服務(wù)

; Automatically add files before PHP document.
; http://php.net/auto-prepend-file
auto_prepend_file = "/path/wwwroot/xhgui-branch/external/header.php"

以上就是Tideways、xhprof 和 xhgui 如何打造 PHP 非侵入式監(jiān)控平臺(tái),小編相信有部分知識(shí)點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見(jiàn)到或用到的。希望你能通過(guò)這篇文章學(xué)到更多知識(shí)。更多詳情敬請(qǐng)關(guān)注億速云行業(yè)資訊頻道。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI