当前位置:知识百科 > 正文

php性能追踪及分析工具

更新时间:2025-01-05 01:26 阅读量:26234
xhprof的安装
下载xhprof,我们这里选择的是通过git clone的方式,当然你也可以从 http://pecl.php.net/package/xhprof 这里下载。

cd /usr/local/src
# 我自己汉化的版本
git clone https://github.com/maxincai/xhgui.git
# 你可以clone原版
git clone https://github.com/phacility/xhprof.git
注意:
php5.4及以上版本不能在pecl中下载,不支持。需要在github上下载hhttps://github.com/phacility/xhprof.git。
另外xhprof已经很久没有更新过了,截至目前还不支持php7,php7可以试使用https://github.com/tideways/php-profiler-extension。

安装xhporof

cd xhprof/extension
/usr/local/php5.6/bin/phpize
./configure --with-php-config=/usr/local/php5.6/bin/php-config --enable-xhprof
make
make install
最后如果出现类似的提示信息,就表示编译安装成功

stalling shared extensions:     /usr/local/php-5.6.14/lib/php/extensions/no-debug-non-zts-20131226/
修改配置文件/etc/php5.6.ini,在最后增加如下配置

[xhprof]
extension=xhprof.so
xhprof.output_dir=/data/www/xhprof/output
重启php-fpm后通过phpinfo查看,或者在命令行通过php -m | grep xhprof查看是否安装成功。

注意:
需要创建output_dir
mkdir -p /data/www/xhprof/output

xhprof的简单用法
将下载的xhprof复制到webroot目录,我这里以/data/www/project-xhprof为例

mkdir /data/www/project-xhprof
cp -R /usr/local/src/xhprof/* /data/www/project-xhprof/
cd /data/www/project-xhprof
在nginx中增加站点配置

server {
        listen  80;
        server_name xhprof.dev;
        root /data/www/project-xhprof;
        index index.php index.html;
        access_log /var/log/nginx/xhprof.dev.log main;
        error_log /var/log/nginx/xhprof.dev.log.err debug;
        rewrite_log on;

        location ~* \.php$ {
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_pass  unix:/var/run/php5.6-fpm.sock;
                fastcgi_index index.php;

        }
}