//修改php的默认时区
date_default_timezone_get('PRC');
//使用微妙计算php脚本执行时间
echo microtime(); echo " 返回当前unix时间戳和微秒数";
echo "<br>";
class Timer{
private $startTime;
private $stopTime;
function __construct(){
$this->startTime=0;
$this->stopTime=0;
}
function start(){
$this->startTime=microtime(true);
}
function stop(){
$this->stopTime=microtime(true);
}
function spent(){
return round(($this->stopTime - $this->startTime),4);
}
}
$timer= new Timer();
$timer->start();
usleep(1000);
$timer->stop();
echo "执行该脚本用时<b>".$timer->spent()."</b>秒<br>";
php 计算脚本执行时间
最新推荐文章于 2021-05-06 16:16:04 发布