Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect internet speed in PHP?

How can I create a PHP page that will detect the user's internet speed and show it on the page? Something like,

Your internet speed is ??? Kbps

like image 417
Sharon Haim Pour Avatar asked Apr 03 '11 12:04

Sharon Haim Pour


People also ask

How to check internet speed PHP?

By user uploading a file to your server. Then you divide file size in kb with time passed in seconds. You then get kb/s (upload speed).

Is 32mb download speed good?

According to the Federal Communications Commission (FCC), a good internet speed is at or above 25 Mbps. These speeds will support most online activity, such as HD streaming, online gaming, web browsing and downloading music.

How do I do a speedtest?

Start testing your speed in seconds by using the Begin Test button on the front page map. This will find a server near you, and test the ping, download speed, and upload speed of your Internet connection.

On which URL you will do Speedtest in?

To use Web Speed, visit the URL of the website that you would like to measure. Open the Speedtest Chrome Extension after or while the website you are visiting loads. The website's Web Speed, as measured in seconds, will appear in the Speedtest Chrome Extension window.


2 Answers

This might not be completely what you're looking for (read the bold part), but I doubt if anything else is possible.

This script sends 512 KB of HTML comments to your client. Parsing that HTML may add to the total transfer time, so don't take this as your raw download speed.

Quoted from: PHP Speed test

Source is here:

http://jan.moesen.nu/code/php/speedtest/index.php?source=1

Hope that helps.

like image 137
Joris Ooms Avatar answered Sep 22 '22 12:09

Joris Ooms


<?php
$kb=1024;
echo "streaming $kb Kb...<!-";
flush();
$time = explode(" ",microtime());
$start = $time[0] + $time[1];
for($x=0;$x<$kb;$x++){
    echo str_pad('', 1024, '.');
    flush();
}
$time = explode(" ",microtime());
$finish = $time[0] + $time[1];
$deltat = $finish - $start;
echo "-> Test finished in $deltat seconds. Your speed is ". round($kb / $deltat, 3)."Kb/s";
?>
like image 41
Martin Avatar answered Sep 23 '22 12:09

Martin