解读PHP计算页面执行时间的具体代码实现_PHP教程

原创
2016-07-15 13:30:00 840浏览

通过对PHP计算页面执行时间的代码如下所示:

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

通过对PHP计算页面执行时间的代码的了解,新手们应该自己再实际操作一遍,以加深自己的理解。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/446322.htmlTechArticle通过对 PHP计算页面执行时间的代码如下所示: ? php classruntime { var$ StartTime = 0 ; var$ StopTime = 0 ; functionget_microtime() { list($usec,$sec)=explode('',mi...
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。