3

我已经使用 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,但仍然没有运气。

4

1 回答 1

2

xhprof.output_dir 字符串

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)符号链接到您的默认虚拟主机根目录。

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

于 2015-09-25T02:03:17.380 回答