PHP Speed Test 用户连接速度测试,当前页面无回显 [英] PHP Speed Test for user connection speed without echo in current page

查看:33
本文介绍了PHP Speed Test 用户连接速度测试,当前页面无回显的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找检查用户连接速度的可能性.应该保存为cookie,如果速度慢的话会适配javascript文件和css文件.

I am looking for a possibility to check the user connection speed. It is supposed to be saved as a cookie and javascript files as well as css files will be adapted if the speed is slow.

我目前测试速度的可能性如下

The possibility for testing speed i have at the moment ist the following

    $kb = 512;

    flush();
    //
    echo "<!-";
    $time = explode(" ",microtime());
    for($x=0;$x<$kb;$x++){
        echo str_pad('', 512, '.');
        flush();
    }
    $time_end = explode(" ",microtime());
    echo "->";

    $start = $time[0] + $time[1];
    $finish = $time_end[0] + $time_end[1];
    $deltat = $finish - $start;

    return round($kb / $deltat, 3);

虽然它有效,但我不喜欢在我的代码中放入这么多字符,如果我回显所有这些,我无法将结果保存在 cookie 中,因为已经有输出.

While it works, I do not like it to put so many characters into my code also if I echo all this I can not save the result in a cookie because there has already been an output.

可以在不同的文件中执行类似的操作吗?你有什么解决办法吗?

Could one do something like this in a different file wor something? Do you have any solution?

提前致谢.

推荐答案

你有什么解决办法吗?

Do you have any solution?

我的解决方案是根本不用进行速度测试.原因如下:

My solution is to not bother with the speed test at all. Here's why:

您说测试的原因是确定要发送哪些 JS/CSS 文件.您必须记住,浏览器会在第一次下载后缓存这些文件(只要它们没有被修改).所以实际上,您正在发送 256K 的测试数据以确定是否应该发送额外的 512K?

You stated that the reason for the test is to determine which JS/CSS files to send. You have to keep in mind that browsers will cache these files after the first download (so long as they haven't been modified). So in effect, you are sending 256K of test data to determine if you should send, say, an additional 512K?

只需发送数据,它就会被缓存.除非您有 MB 的 JS/CSS(在这种情况下您需要重新设计网站,而不是速度测试),否则下载时间是可行的.速度测试应保留用于流式视频等.

Just send the data and it will be cached. Unless you have MBs of JS/CSS (in which case you need a site redesign, not a speed test) the download time will be doable. Speed tests should be reserved for things such as streaming video and the like.

这篇关于PHP Speed Test 用户连接速度测试,当前页面无回显的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆