首页  >  文章  >  后端开发  >  php计算页面执行时间代码

php计算页面执行时间代码

WBOY
WBOY原创
2016-07-25 08:45:071136浏览
  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


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn