Detect internet speed with php

Is it possible to know the internet speed of the visitors with php?
LVL 5
siva_sivaAsked:
Who is Participating?
 
keteracelConnect With a Mentor Commented:
I found this in http://www.2wire.com/bandwidth/initialmeter.php

it's basically javascript and a large html file but should give a good indication.

<html>
<head>
...
</head>
<body>
<<<----- put your HTML for the page here, saying something like "processing". Include an animated gif to make it look like something's happening....

<script>
<!--
      time      = new Date();
      starttime = time.getTime();
// -->
</script>
<!-- a large amount of data here.... try a shakespeare play? -->
<script>
<!--
      time          = new Date();
      endtime       = time.getTime();
      if (endtime == starttime)
            {downloadtime = 0
            }
      else
      {downloadtime = (endtime - starttime)/1000;
      }

      kbytes_of_data = 256; //set this to be the amount of data you put between the <!-- and -->
      linespeed     = kbytes_of_data/downloadtime;
      kbps          = (Math.round((linespeed*8)*10*1.024))/10;

      nextpage='meter.php?kbps=' + kbps;
      document.location.href=nextpage
// -->
</script>
</body>
</html>

So this will basically download the page (quite large) and then run the script to determine how long it took. Thus giving an estimated bandwidth. You could do something nicer with AJAX.
0
 
siva_sivaAuthor Commented:
Large amount of data means what i want to give in this?

I am also visit that site it display bandwidth speed irregularly.

420 kbps, 190 kbps and 556 kbps etc...
0
 
keteracelCommented:
I've tried it 5 times:

3.08Mbps
3.17Mbps
3.13Mbps
3.13Mbps
3.19Mbps

It's pretty consistent. Seems like you've got a pretty variable connection. And I guess it will be more variable with smaller connections.

Also note that your internet traffic will not always go through the same route to the same webpage. So sometimes it'll be randomly slower anyway.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
keteracelCommented:
Might be worth doing several tests, throwing away the fastest and slowest, then average the rest. Give you a better metric.
0
 
nizsmoDeveloperCommented:
Wouldn't the downside though be that they would have to load the actual tester file? If I was on a 56k connection I wouldn't be too happy about that :-)
0
 
keteracelCommented:
Well you'd ideally start with a small file then increase it to get more accurate results for faster bandwidths.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.