添加如下幾行【什麼?找不到php.ini。。。。那就whereis php.ini】:php
[xhprof] extension=xhprof.so xhprof.output_dir="/path/output/dir" #這個目錄是分析性能輸出目錄
.xhprof會將收集到的性能數據按文件(一次數據收集存放一個文件)存放在xhprof.output_dir
指定的目錄(注意添加寫權限)下,並經過xhprof/xhprof_html
目錄下的PHP腳本程序提供網頁形式的展現,因此還需配置web服務提供對該腳本程序的訪問,以Nginx爲例:html
server { listen 8080; server_name localhost; root /path/xhprof/xhprof_html; location / { index index.html index.php; try_files $uri /index.php?$query_string; } location ~ \.php$ { fastcgi_split_path_info ^(.+.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_index index.php; include fastcgi_params; } }
重啓php-fpm && nginx 而後能夠瀏覽器訪問了。這個不用說了吧。。。nginx
xhprof_html提供的Web展現功能能夠提供代碼調用邏輯圖,但依賴於工具dot(即該邏輯圖是使用dot語言寫的),因此須要額外安裝依賴graphviz,例如在CentOS上:yum install graphviz
web
實戰
要對目標PHP程序進行性能分析,須要在程序中注入xhprof提供的方法調用,來收集性能數據,而後經過命令行執行或HTTP請求來觸發。剩下的本身去幹吧。。。好運。瀏覽器