xhprof - PHP性能追蹤及分析工具

環(huán)境

Mac + PHP7 + Nginx

安裝

這里采用的 pecl 方式安裝

// 下載
wget https://pecl.php.net/get/xhprof-2.1.3.tgz
// 安裝
pecl install xhprof-2.1.3.tgz

配置 php.ini

[xhprof]
extension=xhprof.so
# 報(bào)告文件存儲(chǔ)位置,推薦配置一下。不配的話會(huì)使用'系統(tǒng)臨時(shí)目錄' - 從源碼的 `$dir = sys_get_temp_dir();` 得知
xhprof.output_dir=/var/www/xhprof/xhprof_runs/

檢查

  1. php -m
  2. phpinfo() (記得重啟php-fpm)

使用示例

xhprof_enable(XHPROF_FLAGS_MEMORY | XHPROF_FLAGS_CPU);
/**
...
被檢查的php代碼
...
**/
$xhprof_data = xhprof_disable();

// 引入xhprof | 這里的絕對(duì)路徑可以自己 `find / -name xhprof_runs.php` 搜索下
include_once "/usr/local/share/pear/xhprof_lib/utils/xhprof_lib.php";
include_once "/usr/local/share/pear/xhprof_lib/utils/xhprof_runs.php";

$instance = new XHProfRuns_Default(); // 有命名空間的項(xiàng)目可能需要這樣寫(xiě) $instance = new \XHProfRuns_Default();
$run_id = $instance->save_run($xhprof_data, "xhprof");
var_dump($run_id);

配置查看頁(yè)面

  1. nginx 配置
server {
    listen 80;
    server_name xhprof.test.com;
    root /usr/local/share/pear/xhprof_html;
    index index.html index.php;
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi.conf;
    }
}
  1. 查看


相關(guān)鏈接

  1. package xhprof : https://pecl.php.net/package/xhprof
  2. github xhprof :https://github.com/longxinH/xhprof
  3. 參考鏈接 :http://www.itdecent.cn/p/38e3ae81970c
  4. XHProf 報(bào)告字段含義解析 :https://www.jb51.net/article/84456.htm
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容