- class RunTime//頁面執行時間類
- {
- private $starttime;//頁面開始執行時間
- private $stoptime;//頁面結束執行時間
- private $spendtime;//頁面執行花費時間
- function getmicrotime()//獲取返回當前微秒數的浮點數
- {
- list($usec,$sec)=explode(" ",microtime());
- return ((float)$usec + (float)$sec);
- }
- function start()//頁面開始執行函數,返回開始頁面執行的時間
- {
- $this->starttime=$this->getmicrotime();
- }
- function end()//顯示頁面執行的時間
- {
- $this->stoptime=$this->getmicrotime();
- $this->spendtime=$this->stoptime-$this->starttime;
- //return round($this->spendtime,10);
- }
- function display()
- {
- //$this->end();
- echo "<p>運行時間:".round($this->spendtime,10)."秒</p>";
- }
- }
- /*調用方法
- $timer=new Runtime();
- $timer->start();
- $timer->end();
- $timer->display();
新聞熱點
疑難解答