安裝之前確保已經正確安裝了以下軟體
$ sudo pecl install mongodb
PHP 組態檔中新增
[mongodb] extension=mongodb.so
常規編譯安裝
$ 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
$ 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', ... );
$ 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 } )
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; } }
$ 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"; }
; Automatically add files before PHP document. ; http://php.net/auto-prepend-file auto_prepend_file = "/path/wwwroot/xhgui-branch/external/header.php"
更多PHP相關技術文章,請存取PHP教學欄目進行學習!
以上就是Tideways、xhprof 和 xhgui 打造 PHP 非侵入式監控平台的詳細內容,更多請關注TW511.COM其它相關文章!