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

如何使用PHP计算网站(包含所有内容)的加载时间?,php,Php,我需要计算一个网站的加载时间(由它的URL给出)与所有内容(图片等),有人可以帮助吗?使用PHPPHP中的函数可以使它变得更好 $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),

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

PHP中的函数可以使它变得更好

$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.';

我们可以用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>

var timerStart=Date.now();
$(窗口)。加载(函数(){
var time=Date.now()-timerStart;
$('#timeloading').html('在'+时间之后加载的页面);
});
你可以这样做:

$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.';

你做过任何研究和尝试吗?如果没有,你需要先这样做。如果有,您需要共享代码并解释问题。欢迎继续。问之前你试过什么吗?如果是,什么?请阅读指南。关于你的问题,请注意,你可以将这一次与Firefox或Chrome控制台时间进行比较。Magnus Eriksson,我做了一些研究,但唯一得到的是只加载PHP所需的时间Chrome的网络选项卡非常擅长this@apokryfos我可以用PHP吗?这不是OP问题的解决方案。这将只计算PHP在服务器上执行代码所需的时间,而不是加载网页所需的时间(包括图像等,这是OP要求的)。谢谢你的回答,实际上我只想计算由他的URL给出的网站加载时间,我没有codeMagnus Eriksson是的,这是真的,我想计算加载所有内容所需的时间