PHP 使用xhprof 分析程序
PHP增加扩展xhrof
git clone https://github.com/longxinH/xhprof.git ./xhprof
cd xhprof/extension/
/path/to/php7/bin/phpize
./configure --with-php-config=/path/to/php7/bin/php-config
make && sudo make install
PHP配置增加ini
[xhprof]
extension = xhprof.so
xhprof.output_dir = /tmp/xhprof #选填 将分析结果 放到指定文件夹
xhprof.collect_additional_info = 1 #增加收集更多信息
执行代码中加入以下片段 即可进行分析
//开启分析
xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);
/**
* 执行代码块
*/
$XHPROF_ROOT = realpath(dirname(__FILE__) .'/..');
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
// 如果ini里没有设置目录 这里可以设置输出目录
$xhprof_output_dir = $XHPROF_ROOT."/xhprof/run/";
$xhprof_runs = new XHProfRuns_Default($xhprof_output_di();