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

记录页面执行时间php代码

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

  1. class runtime
  2. {
  3. var $StartTime = 0;
  4. var $StopTime = 0;
  5. function get_microtime()
  6. {
  7. list($usec, $sec) = explode(' ', microtime());
  8. return ((float)$usec + (float)$sec);
  9. }
  10. function start()
  11. {
  12. $this->StartTime = $this->get_microtime();
  13. }
  14. function stop()
  15. {
  16. $this->StopTime = $this->get_microtime();
  17. }
  18. function spent()
  19. {
  20. return round(($this->StopTime - $this->StartTime) * 1000, 1);
  21. }
  22. }
  23. //例子
  24. $runtime= new runtime;
  25. $runtime->start();
  26. //你的代码开始
  27. $a = 0;
  28. for($i=0; $i<1000000; $i++)
  29. {
  30. $a += $i;
  31. }
  32. //你的代码结束
  33. $runtime->stop();
  34. echo "页面执行时间: ".$runtime->spent()." 毫秒";
  35. ?>

执行时间, php

人气教程排行