Detect internet speed with php

Posted on 2007-10-09
Last Modified: 2008-01-21
Is it possible to know the internet speed of the visitors with php?
Question by:siva_siva
    LVL 9

    Accepted Solution

    I found this in

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

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

          time      = new Date();
          starttime = time.getTime();
    // -->
    <!-- a large amount of data here.... try a shakespeare play? -->
          time          = new Date();
          endtime       = time.getTime();
          if (endtime == starttime)
                {downloadtime = 0
          {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;
    // -->

    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.
    LVL 5

    Author Comment

    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...
    LVL 9

    Expert Comment

    I've tried it 5 times:


    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.
    LVL 9

    Expert Comment

    Might be worth doing several tests, throwing away the fastest and slowest, then average the rest. Give you a better metric.
    LVL 21

    Expert Comment

    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 :-)
    LVL 9

    Expert Comment

    Well you'd ideally start with a small file then increase it to get more accurate results for faster bandwidths.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now