Heim  >  Artikel  >  Backend-Entwicklung  >  记录页面执行时间php代码

记录页面执行时间php代码

WBOY
WBOYOriginal
2016-07-25 08:46:02742Durchsuche
  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{
  29. $a += $i;
  30. }
  31. //你的代码结束
  32. $runtime->stop();
  33. echo "页面执行时间: ".$runtime->spent()." 毫秒";
  34. ?>
复制代码

执行时间, php


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:任意格式文件下载 Nächster Artikel:快速安装php7 的shell脚本