您的位置:首页 > 编程语言 > PHP开发

windows 64位PHP5.5配置xhprof

2016-03-30 17:00 507 查看
windows 64位PHP5.5配置xhprof。

1.首先下载xhprof拓展,下载地址:http://windows.php.net/downloads/pecl/releases/xhprof/0.10.6/ ,选择对应的版本下,我本地是win64,PHP5.5 这里选择的是php_xhprof-0.10.6-5.5-ts-vc11-x64.zip,解压把php_xhprof.dll放到php\ext下,修改php.ini文件,在最低部加入下面代码:

[xhprof]
extension=php_xhprof.dll
; directory used by default implementation of the iXHProfRuns
; interface (namely, the XHProfRuns_Default class) for storing
; XHProf runs.
xhprof.output_dir="D:/wamp/www/xhprof_log"其中xhprof.output_dir的路径可以随便选择,但是要提前创建出该文件夹,注意不要有空格或中文,D:\wamp\www\xhprof_log为文件夹,运行xhprof时生成文件在该文件夹下。
重启apache,phpinfo()查看是否加载xhprof

2.下载xhprof日志记录的项目代码,地址:http://pecl.php.net/get/xhprof-0.9.4.tgz,解压把项目放到www目录下,项目包含示例代码,我这里把解压项目放到www目录下,并在www下创建sample.php,编辑代码:

<?php

// 运行的函数
function bar($x) {
$x++;
}

// 运行的函数
function foo() {
for ($idx = 0; $idx < 5; $idx++) {
bar($idx); // 这里意思为运行的函数再调用子函数,xhprof也会统计子函数的运行情况
}
}

// 开启记录
xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);

// 运行用户的操作函数
foo();

// 结束统计记录并返回统计结果
$xhprof_data = xhprof_disable();

/* 引入xhprof统计结果的项目,把统计结果存入日志文件中
* 该项目还有统计结果的展示页,访问地址为:http://localhost/xhprof/xhprof_html/index.php
*/
$XHPROF_ROOT = realpath(dirname(__FILE__) .DIRECTORY_SEPARATOR.'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_foo");

// run_id为日志文件的文件名
echo $run_id;
/* 结束保存记录日志 */
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: