Discuz教程网

PHP代码运行时间查看类代码分享

[复制链接]
authicon dly 发表于 2011-9-3 19:03:50 | 显示全部楼层 |阅读模式
代码如下:

  1. //date:2011-08-05
  2. class RunTime//页面执行时间类
  3. {
  4. private $starttime;//页面开始执行时间
  5. private $stoptime;//页面结束执行时间
  6. private $spendtime;//页面执行花费时间
  7. function getmicrotime()//获取返回当前微秒数的浮点数
  8. {
  9. list($usec,$sec)=explode(" ",microtime());
  10. return ((float)$usec + (float)$sec);
  11. }
  12. function start()//页面开始执行函数,返回开始页面执行的时间
  13. {
  14. $this->starttime=$this->getmicrotime();
  15. }
  16. function end()//显示页面执行的时间
  17. {
  18. $this->stoptime=$this->getmicrotime();
  19. $this->spendtime=$this->stoptime-$this->starttime;
  20. //return round($this->spendtime,10);
  21. }
  22. function display()
  23. {
  24. //$this->end();
  25. echo "<p>运行时间:".round($this->spendtime,10)."秒</p>";
  26. }
  27. }
  28. /*调用方法
  29. $timer=new Runtime();
  30. $timer->start();
复制代码







上一篇:PHP header函数分析详解
下一篇:discuz程序的PHP加密函数原理分析
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 20:07

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表