欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

获得页面执行时间

程序员文章站 2022-05-21 19:16:54
...
获得页面执行时间
header("Content-type:text/html;charset=utf-8");
class runtime
{
private $begintime = 0;
private $endtime = 0;
private function gettime()
{
list($usec,$sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
public function begin()
{
$this->begintime = $this->gettime();
}
public function end()
{
$this->endtime = $this->gettime();
}
public function spent()
{
return round(($this->endtime - $this->begintime) * 1000, 1);
}
}
$runtime = new runtime();
$runtime->begin();
for ($i=0; $i echo $i;
}
$runtime->end();
echo '页面执行时间'.$runtime->spent().'毫秒';
?>

AD:真正免费,域名+虚机+企业邮箱=0元