php简单计算页面加载时间的方法

这篇文章主要介绍了php简单计算页面加载时间的方法,涉及php针对页面加载时间的计算技巧,需要的朋友可以参考下。

本文实例讲述了php简单计算页面加载时间的方法,分享给大家供大家参考,具体实现方法如下:

简单的把开始时间放在页面头部,结束时间放在页面尾部,计算页面加载时间

  1. $start = time();
  2. // put a long operation in here
  3. sleep(2);
  4. $diff = time() - $start;
  5. print "This page needed $diff seconds to load :-)";
  6. // if you want a more exact value, you could use the
  7. // microtime function