使用 PHP/Javascript 测试网络速度

发布于 2024-11-26 13:54:54 字数 178 浏览 2 评论 0原文

我正在尝试找到一种使用 PHP 或 Javascript 测试网络速度的方法。

这可能吗?

理想情况下,我想测试速度并动态决定向客户端交付多少内容......

我应该指出我主要是在谈论移动设备。大多数宽带连接差别很小,所以我的目的是判断某人是否连接到 WiFi 网络或在蜂窝数据网络上遇到困难。

I'm trying to find out a way to test network speed using PHP or Javascript.

Is this possible?

I'd ideally like to test the speed and the dynamically decide how much content to deliver to the client...

I should point out i'm largely talking about mobile devices. Most broadband connection differ very little so i'm aiming to gauge whether someone is connected to a WiFi network or is struggling on Cellular data network.

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

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

发布评论

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

评论(2

榆西 2024-12-03 13:54:54

执行 ajax 请求来下载固定大小的数据块并检查之前/之后的时间以大致了解速度:

var start = new Date();
$.ajax(....);
var end = new Date();

var elapsed = end.getTime() - start.getTime(); // elapsed time in milliseconds.

您需要使用足够大的数据块来获取有效的请求,这意味着您只是为了进行此测试而浪费了相当多的带宽。

Do an ajax request to download a fixed-size chunk of data and check the time before/after to get a rough idea of speeds:

var start = new Date();
$.ajax(....);
var end = new Date();

var elapsed = end.getTime() - start.getTime(); // elapsed time in milliseconds.

You'd need to use a large enough chunk of data to get valid requests, which'd mean you're wasting a fair amount of bandwidth just to do this test.

不奢求什么 2024-12-03 13:54:54

他们的方式我认为,你可以使用 JS -> PHP-> JS 调用并对响应计时,但这是相当不准确的。此外,您需要使用相当数量的数据(过多的带宽使用问题),并且由于浏览器之间存在/不存在服务器标头,因此永远不会得到明确的答案。服务提供商( comcast )还存在一个问题,他们在前几秒为您提供 12 MB 的速度,但随后将您降至 3 MB,所以现在您的“测试”会说它们位于 OC 线路上,但流本身现在会出现数据不足并不断缓冲。

最好的解决方案是在流协议中构建逻辑,该逻辑可以根据传入的数据量进行调整。也许它以较低的带宽质量开始,并在发现缓冲区增长速度快于带宽质量时提高标准。正在播放数据(Hulu、YouTube 或 Amazon 视频就是这样做的)。

They way I see it, you can use JS -> PHP -> JS call and time the response, but that is pretty inaccurate. Also, you'd need to use a fair amount of data (excess bandwidth usage concerns) and would never get an explicit answer due to server headers that exist/don't exist between browsers. There's also a concern with service providers (cough comcast cough) where they give you 12 mbit speeds for the first few seconds, but choke you down to 3mbits afterward, so now your "Test" would say they're on an OC line but the stream itself would now have a data deficit and be buffering constantly.

The best solution is to build the logic in to the streaming protocol that can adjust based on how much/little data is coming in. Maybe it starts out at a low bandwidth quality and raises the bar when it notices the buffer is growing faster than the data is playing (this is what Hulu, YouTube or Amazon video do).

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