<?php error_reporting(E_ALL); class RunTime{ private $startTime=''; private $endTime=''; function __construct() { $this->startTime = $this->getMicroTimeAsFloat(); } function getMicroTimeAsFloat(){ list($fractionalSeconds,$seconds)=explode(" ", microtime()); return ((float)$seconds + (float)$fractionalSeconds); } function elapsed(){ $this->endTime = $this->getMicroTimeAsFloat(); return ($this->endTime - $this->startTime); } } 运行方式:引入该类,在页面头部初始化,$rt= new Runtime(); 页面底部显示 echo $rt->elapsed();