自己随手写的一个计算脚本/页面执行时间的类,贴出来希望对有些朋友有用。

// *************************
// Class processtime
// www.code-life.com
// *************************
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).';
Tags: ,
B Homepage
2008/04/27 07:28
这个类确实有用,有的时候能派上用场
分页: 1/1 第一页 1 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
昵称   密码   游客无需密码
网址   电邮   [注册]
               

验证码 不区分大小写