使用 PHP 测试服务器加载时间?

发布于 2024-09-10 17:41:35 字数 369 浏览 3 评论 0原文

有没有办法确定使用 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 加载网页(包括图像或视频)需要多长时间?

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

Is there a way to determine how long it takes a web page, and all it's content, to load with PHP?

I have already tried this:

$time_start = microtime(true);

(All the content of the web page here)

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

However, the problem with this (as far as I can tell) is that I'm only calculating the time it takes the php script to execute. This doesn't factor in any images or videos that are on the page.

Is there a way to determine how long it takes a web page to load including images or videos using php?

Basically what I'm trying to do is test the speed of my server with out factoring in my connection speed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

一腔孤↑勇 2024-09-17 17:41:35

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

You need to download firebug and then open the "net" tab and wait for the page to finish loading and it will show you the total load time of all requests.

此生挚爱伱 2024-09-17 17:41:35

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

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

You might consider ab (ApacheBench). It's for testing the performance of your web server, but you can run it against a particular URL if you're just concerned about one page. One advantage is that it can run from the command line and issue multiple requests in parallel, enabling you to do some kind of load testing.

If you want to factor in how long it takes to actually load on the browser, you'll need some kind of javascript solution. One approach with code is presented in the article, Optimizing Page Load Time, which is worth reading.

悲念泪 2024-09-17 17:41:35

Google Chrome 内置了一个令人惊叹的审核工具,它提供了一系列改进给定网站速度的方法。
替代文本 http://far.id.au/audit.png

Google Chrome has an amazing Audit tool built in which gives a good list of ways to improve a given site as far as speed goes.
alt text http://far.id.au/audit.png

空城之時有危險 2024-09-17 17:41:35

试试这个

// 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.';
?>

try this

// 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.';
?>
£烟消云散 2024-09-17 17:41:35

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

或者使用诸如webpagetest.org之类的综合测试工具来收集来自各种浏览器/位置/网络的计时变化

You can either use the NavigationTiming API (https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming2/Overview.html) and beacon the timings back - this is how boomerang works (https://github.com/lognormal/boomerang)

Alternatively use a synthetic test tool like webpagetest.org to gather timings from various browsers/locations/network variations

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文