有没有什么方法可以得到一个测量本地主机页面渲染时间的php脚本。我已经搜索过,但没有找到任何东西,可能是因为我不知道如何搜索这种脚本。
关于原始已批准答案的更新(针对未来搜索并复制粘贴 mojo 的人):
对于 PHP 5.X+,您不仅需要将“true”作为参数添加到microtime()变量中,而且我们不再需要将其除以1,000。所以2013年的答案是:
脚本的开头:
$start = microtime(true);
脚本底部:
$end = microtime(true);
$creationtime = ($end - $start);
printf("Page created in %.6f seconds.", $creationtime);
$start = microtime();
$end = microtime();
$creationtime = ($end - $start) / 1000;
printf("Page created in %.5f seconds.", $creationtime);
您无法使用PHP测量浏览器渲染时间。您所能做的只是测量服务器生成页面所需的时间。
但如果可以使用Javascript,可以执行以下操作:
<html>
<head>
<script type="text/javascript">
var start_time=+new Date();
window.onload=function(){
alert("Page render time: " + ((+new Date()-start_time)/1000));
};
</script>
</head>
<body>
<p>hi</p>
</body>
</html>