1

有没有办法确定使用 PHP 加载网页及其所有内容需要多长时间?

我已经尝试过这个:

$time_start = microtime(true);

(All the content of the web page here)

$time_end = microtime(true);
$time = $time_end - $time_start;
echo $time;

但是,这个问题(据我所知)是我只计算执行 php 脚本所需的时间。这不考虑页面上的任何图像或视频。

有没有办法确定使用 php 加载包括图像或视频在内的网页需要多长时间?

基本上我想要做的是测试我的服务器的速度,而不考虑我的连接速度。

4

5 回答 5

4

您需要下载firebug然后打开“net”选项卡并等待页面完成加载,它会显示所有请求的总加载时间。

于 2010-07-23T05:16:13.843 回答
1

您可以考虑使用ab (ApacheBench)。它用于测试 Web 服务器的性能,但如果您只关心一个页面,则可以针对特定 URL 运行它。一个优点是它可以从命令行运行并并行发出多个请求,使您能够进行某种负载测试。

如果您想考虑在浏览器上实际加载需要多长时间,您将需要某种 javascript 解决方案。文章“优化页面加载时间”中介绍了一种使用代码的方法,值得一读。

于 2010-07-23T05:12:59.457 回答
1

谷歌浏览器内置了一个惊人的审计工具,它提供了一个很好的方法列表来改善给定网站的速度。 替代文字 http://far.id.au/audit.png

于 2010-07-23T06:31:57.743 回答
0

尝试这个

// top of the page --
<?php
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$start = $time;
?>

// end of the page --
<?php
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start), 4);
echo 'Page generated in '.$total_time.' seconds.';
?>
于 2014-02-16T15:02:14.823 回答
0

您可以使用 NavigationTiming API ( https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming2/Overview.html ) 并将计时返回 - 这就是回旋镖的工作原理 ( https: //github.com/lognormal/boomerang )

或者使用综合测试工具(如webpagetest.org)从各种浏览器/位置/网络变化中收集时间

于 2014-02-20T13:37:52.507 回答