php xhprof使用教程

1 安装xhprof扩展,并修改php.ini

[xhprof]
extension=xhprof.so
xhprof.output_dir=/tmp

2 配置nginx
将xhprof安装包中的xhprofhtml和xhproflib两个目录复制到网站的根目录下

    server {
        listen       80;
        server_name  _;

        root   /vagrant;
        index  index.html index.htm index.php;
        
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }


        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

    }

3 修改代码,引用分析工具

xhprof_enable();
...
$xhprofData = xhprof_disable();
require '/vagrant/xhprof/xhprof_lib/utils/xhprof_lib.php';
require '/vagrant/xhprof/xhprof_lib/utils/xhprof_runs.php';

$xhprofRuns = new XHProfRuns_Default();
$runId = $xhprofRuns->save_run($xhprofData, 'xhprof');

echo 'http://localhost/xhprof/xhprof_html/index.php?run=' . $runId . '&source=xhprof';

4 执行脚本后,生成的$runId就是本次分析结果的id,据此访问链接:

'http://localhost/xhprof/xhprof_html/index.php?run=' . $runId . '&source=xhprof_test'
发布了24 篇原创文章 · 获赞 0 · 访问量 3372

猜你喜欢

转载自blog.csdn.net/GuXiaoyan12/article/details/103589539
今日推荐