如何使用PHP计算网站(包含所有内容)的加载时间?

时间:2019-02-27 08:13:06

标签: php

我需要计算一个网站的加载时间(由他的URL给出)以及所有内容(图片等),任何人都可以帮忙吗?使用PHP

3 个答案:

答案 0 :(得分:1)

U可以这样做:

$start = microtime(true); // Put it from the begining of the page

// Your ccontent

$finish = microtime(true); // Put it in the very end of the page

$total_time = round(($finish - $start), 4);
echo 'Page generated in '.$total_time.' seconds.';

答案 1 :(得分:0)

php中的microtime函数可以使其变得更好

$start = microtime(true); // Put it from the begining of the page

// Your code

$finish = microtime(true); // Put it in the very end of the page

$total_time = round(($finish - $start), 4);
echo 'Page generated in '.$total_time.' seconds.';

答案 2 :(得分:0)

我们可以使用javascript,我正在使用jquery

<!DOCTYPE html>
<head>

  <script type="text/javascript">
    var timerStart = Date.now();
  </script>
</head>
  <!-- put everything you need in here -->
  <div id="timeloading"></div>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"> 
  </script>

  <script type="text/javascript">
    $(window).load(function() {
      var time = Date.now()-timerStart;
      $('#timeloading').html('Page loaded after '+ time);
    });
  </script>
</body>
</html>
相关问题