实现方法一:
/**
* 获取页面执行时间
* edit www.jbxue.com
*/
$t = new executeTime;
phpinfo();
class executeTime{
private $microtime;
public function __construct(){
$this->microtime = microtime(true);
}
public function getNow(){
$this->__dectruct();
}
public function __destruct(){
if (empty($_SERVER['REQUEST_TIME_FLOAT']))
echo '
本次执行时间:', microtime(TRUE) - $this->microtime, '秒
';
else
echo '
本次执行时间:', microtime(TRUE) - $_SERVER['REQUEST_TIME_FLOAT'], '秒
';
}
}
另一种方法:
$pagestartime=microtime();
?>
网页内容
...
...
$pageendtime = microtime();
$starttime = explode(" ",$pagestartime);
$endtime = explode(" ",$pageendtime);
$totaltime = $endtime[0]-$starttime[0]+$endtime[1]-$starttime[1];
$timecost = sprintf("%s",$totaltime);
echo "页面运行时间: $timecost 秒";
?>