使用 PHP 测试服务器加载时间?
有没有办法确定使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您需要下载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.
您可能会考虑 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.
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
试试这个
try this
您可以使用 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