PHP Speed Test for user connection speed without e

2020-03-19 02:25发布

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);

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?

Thanks in advance.

7条回答
▲ chillily
2楼-- · 2020-03-19 03:28

The only idea what i can come up is a redirect.

  • Measure users' speed
  • Redirect to index

While this isn't a nice solution it only need to measure users' speed only once so i think it's excusable.

查看更多
登录 后发表回答