获得页面执行时间

<?php
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 < 10055; $i++) { 
    echo $i;
}
$runtime->end();
echo '页面执行时间'.$runtime->spent().'毫秒';
?> 

 

相关文章:

  • 2021-12-24
  • 2021-07-11
  • 2021-10-30
  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-23
  • 2021-08-23
  • 2021-06-24
  • 2022-12-23
  • 2021-09-01
相关资源
相似解决方案