当前位置:首页 > PHP计算页面执行时间

PHP计算页面执行时间

点击次数:1762  更新日期:2011-01-02
\n

以下类定义了一个计时器,将你的执行脚本加入到”容器”内即可(请看注释)


\n<?
\n
class timer
\n
{ var StartTime = 0;
\nvar
StopTime = 0;
\nvar
TimeSpent = 0;

\n

function start(){
\n
this->StartTime = microtime();}
\n function
stop(){
\n
this->StopTime = microtime();}
\n function
spent(){
\n if (
this->TimeSpent) {
\n return
this->TimeSpent;
\n } else {
\n
StartMicro = substr(this->StartTime,0,10);
\n
StartSecond = substr(this->StartTime,11,10);
\n
StopMicro  = substr(this->StopTime,0,10);
\n
StopSecond = substr(this->StopTime,11,10);
\n
start = doubleval(StartMicro) + StartSecond;
\n
stop = doubleval(StopMicro) + StopSecond;
\n
this->TimeSpent = stop - start;
\nreturn
substr(this->TimeSpent,0,8).“秒”;
\n }
\n }
// end function spent();
\n
}//end class timer;
\n//例子
\n
timer = new timer;
\n
timer->start();
\n
/*
\n你的代码放在此处
\n*/

\n

timer->stop();
\necho
“执行本SCRIPT共”.timer->spent();
\n
?>

\n