1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#下载安装xhprof wget http://pecl.php.net/get/xhprof-0.9.4.tgz tar -zxvf xhprof-0.9.4.tgz cd xhprof-0.9.4/extension/ phpize -> ./configure -> make -> make install #配置php.ini [xhprof] extension=xhprof.so ;日志输出目录,需要加上写入权限 xhprof.output_dir=/home/wwwlogs/xhprof #安装绘图工具 yum install graphviz #将解压包中的xhprof_html和xhporf_lib复制到相应web目录 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<?php //开始测试 beginXhprof(); //一些代码... //结束测试 endXhprof(); function beginXhprof() { include_once '/home/wwwroot/default/xhporf/xhprof_lib/utils/xhprof_lib.php'; include_once '/home/wwwroot/default/xhporf/xhprof_lib/utils/xhprof_runs.php'; xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); } function endXhprof($profiler_namespace = 'xhprof') { $xhprof_data = xhprof_disable(); $xhprof_runs = new XHProfRuns_Default(); $run_id = $xhprof_runs->save_run($xhprof_data, $profiler_namespace); $profiler_url = sprintf('http://192.168.22.228/xhporf/xhprof_html/index.php?run=%s&source=%s', $run_id, $profiler_namespace); echo '<br>' . $profiler_url; } |
http://aofengblog.blog.163.com/blog/static/6317021201341851510578/