如何让XHprof开始分析?

时间:2015-09-22 23:58:09

标签: php xhprof

我使用php5-xhprof

在debian 7上安装了xhprof

这创建了一个文件/etc/php5/fpm/conf.d/20-xhprof.ini

在那个ini文件中我添加了xhprof.output_dir =“/ tmp / xhprof”

我使用755 www-data:www-data

创建了文件/ tmp / xhprof

我可以确认php已经使用phpinfo()启用了xhprof,虽然它没有给我output_dir参数。

我运行第一行的脚本

xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);

/ tmp / xhprof

中没有创建文件

我已经重启了php5-fpm但仍然没有运气。

1 个答案:

答案 0 :(得分:0)

  

xhprof.output_dir string

     

iXHProfRuns接口的默认实现(即XHProfRuns_Default类)用于存储XHProf运行的目录。

http://php.net/manual/en/xhprof.configuration.php

在分析(或脚本)结束时,您需要手动保存数据

$xhprof_data = xhprof_disable();

$XHPROF_ROOT = "/tools/xhprof/";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";

$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_testing");

echo "http://localhost/xhprof/xhprof_html/index.php?run={$run_id}&source=xhprof_testing\n";

http://php.net/manual/en/xhprof.examples.php

如果您不想控制应用程序代码中的分析,则可以制作一个自动加载的代码段/path/to/xhprof/xhprof_enabler.php

<?php

xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);

register_shutdown_function(function(){
    $xhprof_data = xhprof_disable();

    $XHPROF_ROOT = "/path/to/xhprof";
    include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
    include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";

    $xhprof_runs = new XHProfRuns_Default();
    $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_testing");

    echo "http://localhost/xhprof/xhprof_html/index.php?run={$run_id}&source=xhprof_testing";
});

然后添加

auto_prepend_file=/path/to/xhprof/xhprof_enabler.php

/etc/php5/fpm/conf.d/20-xhprof.ini

请注意,您还需要设置虚拟主机以查看配置文件,或者您可以将xhprof文件夹(包含xhprof_html)符号链接到默认的vhost根目录。

重新启动php5-fpm,您应该完成。

相关问题