//方法二
//方法三
class timer { var $starttime = 0; var $stoptime = 0; var $timespent = 0;
function start(){ $this->starttime = microtime();} function stop(){ $this->stoptime = microtime();} function spent(){ if ($this->timespent) { return $this->timespent; } else { $startmicro = substr($this->starttime,0,10); $startsecOnd= substr($this->starttime,11,10); $stopmicro = substr($this->stoptime,0,10); $stops教程econd = substr($this->stoptime,11,10); $start = doubleval($startmicro) + $startsecond; $stop = doubleval($stopmicro) + $stops教程econd; $this->timespent = $stop - $start; return substr($this->timespent,0,8)."秒"; } }// end function spent(); }//end class timer; //例子 $timer = new timer; $timer->start(); /* 你的代码放在此处 */
$timer->stop(); echo "执行本script共".$timer->spent();