正在加载...

PHP脚本/页面执行时间类

[ 2010/02/06 01:28 | by selboo ]

计算脚本/页面执行时间的类,贴出来希望对有些朋友有用。

class processtime {
  var $starttime, $endtime;
  function start() {
    $this->starttime = $this->nowtime();
  }
  function end() {
    $this->endtime = $this->nowtime();
  }
  function elapsed() {
    $processtime = $this->endtime - $this->starttime;
    return number_format($processtime, 7);
  }
  function nowtime() {
    $now = explode(" ", microtime());
    return $now[1] + $now[0];
  }
}

==== 使用方法 ====
在脚本/页面开始处创建一个实例:

$itime = new processtime;

在脚本/页面开始和结束处分别调用start()和end()方法:

$itime->start();
/*
SOME CODE HERE
*/
$itime->end();

在需要显示的位置调用elapsed()方法:

echo 'Processed in '.$itime->elapsed().' second(s).';

最后编辑: selboo 编辑于2010/05/25 17:04
Tags: ,
,
发表评论
表情
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]