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

php计算页面执行时间代码

程序员文章站 2022-05-25 22:01:10
...
  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