- 先到LAMPP官网下载LAMPP
- 到PHP官网下载xhprof
- 解压xhprof
- 在命令行中进入到 xhprof-0.9.4/extension目录
- 继续输入:sudo /opt/lampp/bin/phpize
- ./configure --with-php-config=/opt/lampp/bin/php-config --prefix=/opt/lampp/
- make
- make test
- make install
-
之后就会看到安装完成的提示。去 /opt/lampp/lib/php/extensions/no-debug-on-zts-20060613/ 下查看,会看到已经有 xhprof.so 了。
- 在 /opt/lampp/etc/php.ini 中添加
extension="xhprof.so" ,(注:如果是64位系统需要将xhprof.so文件拷贝到相关的lib64的目录下)
xhprof.output_dir="/tmp/xhprof"(如果TMP目录下没有XHPROF目录要创建目录,否则会报错)
重启lampp。 - 重启服务器后,就可以看到phpinfo中xhprof的信息了。
开始测试
- 将代码加入到要测试的php当中
<?php xhprof_enable ( XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY ); //下面是要测试的代码 function demo(){ sleep(3); echo "xixi"; echo "<br/>"; } demo(); //上面是要测试的代码 $xhprofData = xhprof_disable (); //下面的include_once中的目录,需要自定义 include_once "/opt/lampp/htdocs/xhprof/xhprof_lib/utils/xhprof_lib.php"; include_once "/opt/lampp/htdocs/xhprof/xhprof_lib/utils/xhprof_runs.php"; $xhprofRuns = new XHProfRuns_Default (); $run_id = $xhprofRuns->save_run ( $xhprofData, "xhprof" ); //在浏览器直接打开这个链接就可以查看性能分析结果。 echo "http://localhost/xhprof/xhprof_html/index.php?run={$run_id}&source=xhprof\n"; ?>
<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier new';"><span style="font-family:'Courier new';"> 下面是一些参数说明 Inclusive Time 包括子函数所有执行时间。 Exclusive Time</span>/<span style="font-family:'Courier new';">Self Time 函数执行本身花费的时间,不包括子树执行时间。 Wall Time 花去了的时间或挂钟时间。 CPU Time 用户耗的时间</span>+<span style="font-family:'Courier new';">内核耗的时间 Inclusive CPU 包括子函数一起所占用的CPU Exclusive CPU 函数自身所占用的CPU</span>