当前位置:Gxlcms > PHP教程 > php计算页面执行时间代码

php计算页面执行时间代码

时间:2021-07-01 10:21:17 帮助过:24人阅读

  1. class c_Timer {
  2. var $t_start = 0;
  3. var $t_stop = 0;
  4. var $t_elapsed = 0;
  5. function start() { $this->t_start = microtime(); }
  6. function stop() { $this->t_stop = microtime(); }
  7. function elapsed() {
  8. if ($this->t_elapsed) {
  9. return $this->t_elapsed;
  10. } else {
  11. $start_u = substr($this->t_start,0,10);
  12. $start_s = substr($this->t_start,11,10);
  13. $stop_u = substr($this->t_stop,0,10);
  14. $stop_s = substr($this->t_stop,11,10);
  15. $start_total = doubleval($start_u) + $start_s;
  16. $stop_total = doubleval($stop_u) + $stop_s;
  17. $this->t_elapsed = $stop_total - $start_total;
  18. return $this->t_elapsed;
  19. }
  20. }
  21. };
  22. /* Here's an example usage:
  23. $timer = new c_Timer;
  24. $timer->start();
  25. echo "
    ";
  26. $timer->stop();
  27. echo $timer->elapsed();
  28. */
  29. ?>

执行时间, php

人气教程排行