添加如下几行【什么?找不到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请求来触发。剩下的本身去干吧。。。好运。浏览器