wget http://pecl.php.net/get/xhprof-0.9.4.tgz
tar zxvf xhprof-0.9.4.tgz
(2)编译和运行
cd xhprof-0.9.4/extension/
phpize //此语句编译PHP扩展的工具,主要是根据系统信息生成对应的configure文件,一般存放在/usr/local/php/bin/目录下
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
mkdir /tmp/xhprof
//找到你要分析的代码,在代码开始处添加,start profiling,将会统计内存占用情况
xhprof_enable(XHPROF_FLAGS_MEMORY);
//具体代码
//在代码结束位置添加
$xhprof_data = xhprof_disable(); // stop profiler, display raw xhprof data for the profiler run
include_once ("/usr/local/src/xhprof-0.9.4/xhprof_lib/utils/xhprof_lib.php"); # 请注意设置站点 include_path 权限
include_once ("/usr/local/src/xhprof-0.9.4/xhprof_lib/utils/xhprof_runs.php");
$xhprof_runs = new \XHProfRuns_Default();
// Save the run under a namespace "xhprof_foo".
// **NOTE**:
// By default save_run() will automatically generate a unique
// run id for you. [You can override that behavior by passing
// a run id (optional arg) to the save_run() method instead.]
$xhprof_runs->save_run($xhprof_data, "xhprof_foo");