Ads

Creating your own Broadban Speed test

In this tutorial you will learn how to create and construct your own broadban speed test.

You may find examples here of a broadban speed test:
1. www.speedtest.net/
2. www.speakeasy.net/speedtest/
3. www.bandwidthplace.com/speedtest/
4. www.intel.com/ca/personal/digital-life/broadband/index.htm
5. www.bandwidthplace.com/speedtest/
6. www.dslreports.com/stest

There is so many more out there on the net. Tho ours will not be as complicated as theirs.

In theory it would be quite easy to create a broadban speed test. Basically what you are doing is sending the 'visitor' a small packet of information and seeing how long it would take to send to that 'visitor'.

Now first off we're going to set our default_kbyte_test_size to 512. This can be anything but this time we're setting it to 512.


CODE
<?php  
$default_kbyte_test_size 
512;  
?> 



If your interested in computer sizes you can have a look here.. http://www.geocities.com/~budallen/byte.html They have some good information on & about it.

Next lets start creating the html page.


CODE
<html>  
        <head>  
                <title>TotalDream Bandwidth Speed Test</title>  
                <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">  
                <META HTTP-EQUIV="Expires" CONTENT="Fri, Jun 12 1981 08:20:00 GMT">  
                <META HTTP-EQUIV="Pragma" CONTENT="no-cache">  
                <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">  
        </head>  

        <body>  



This above lets the browser know that the page has expires wayy ago, the content-type is text/html windows charset 1252 and their is no cache on this page.

Now the next thing we need to do is display our 'Testing in progress' text.

CODE
                <center>  
<br><br><br><br><br><br>  
             Testing Your Current Bandwidth...  


You may change this to whatever you please...

Next comes the javascript.

CODE
<script language="JavaScript">  
<!--  
        time      = new Date();  
        starttime = time.getTime();  
// -->  
</script>  


This gets the start time of the test in javascript.

You will need to create a file to be exact, an .ZIP file that is atleast 3 MB's in size and filled with junk binary and upload it to that directory that the speed test is in.

Remember to change A_Sample_binary_file.zip to whatever the name of the junk file is.

Here's the php:

CODE
<?php  
    
// $data_file Should Be A Junk Binary File, We Tested It With a 3 MB file.  
    //Use Any Binary File And Just Rename It  

        
$data_file "A_Sample_binary_file.zip";  
        
$fd fopen ($data_file"rb+");  
        
$test_kbytes $default_kbyte_test_size;  
        
$contents fread ($fd$test_kbytes 1024);  
                 
        echo 
"<!-- $contents -->";  
        
fclose ($fd);  

?>  



The above takes the junk file, opens it, finds out what size we set at the top of the page, and reads the file using that file size we set. It basically echo's the contents of the file onto the page (but dosnt show you), then closes the connection to the file.

Next comes some more javascript.

CODE
<script language="JavaScript">  
<!--  
        time          = new Date();  
        endtime       = time.getTime();  
        if (endtime == starttime)  
                {downloadtime = 0  
                }  
        else  
        {downloadtime = (endtime - starttime)/1000;  
        }  

        kbytes_of_data = <?php echo $test_kbytes?>;  
        linespeed     = kbytes_of_data/downloadtime;  
        kbps          = (Math.round((linespeed*8)*10*1.024))/10;  
        nexturl = 'index.php?kbps='+ kbps;  
    //alert(kbytes_of_data);  
    document.location.href=nexturl;  
// -->  
</script>  


This gets a new date at the end of the test, then subtracts the endtime from the starttime and divides it from 1000. Next it takes the 'kbytes' of data we set at the top of the page, divides it by the download time, does some other math work.

*NOTICE: Don't forget to change the 'nexturl' to whatever your URL of that page is. The speed test wont work if you don't.

Next the javascript reloads the page with a different file size to test with, different from the one we set at the top of the page.

Finally lets end this page and move on.

CODE
<center>  
</body>  
</html>  
<?php  
}  
?>



Now we're just closing up our html we started earlyer on, and closing the php as well.

Here is our full & final code:

CODE
<?php  
$default_kbyte_test_size 
512;  
?>  
<html>  
        <head>  
                <title>Bandwidth Test</title>  
                <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">  
                <META HTTP-EQUIV="Expires" CONTENT="Fri, Jun 12 1981 08:20:00 GMT">  
                <META HTTP-EQUIV="Pragma" CONTENT="no-cache">  
                <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">  
                <link rel="stylesheet" href="style.css">  
        </head>  

        <body>  
                <center>  
<br><br><br><br><br><br>  
                                                Testing Your Current Bandwidth...  

<script language="JavaScript">  
<!--  
        time      = new Date();  
        starttime = time.getTime();  
// -->  
</script>  

<?php  
    
// $data_file Should Be A Junk Binary File I Tested It With a 3 MB file.  
    //Use Any Binary File And Just Rename It  
    //I Just Used A ZIpped Backup File Of Mine  
        
$data_file "A_Sample_binary_file.zip";  
        
$fd fopen ($data_file"rb+");  

        
$test_kbytes $default_kbyte_test_size;  

        
$contents fread ($fd$test_kbytes 1024);  
                 
        echo 
"<!-- $contents -->";  
        
fclose ($fd);  

?>  
<script language="JavaScript">  
<!--  
        time          = new Date();  
        endtime       = time.getTime();  
        if (endtime == starttime)  
                {downloadtime = 0  
                }  
        else  
        {downloadtime = (endtime - starttime)/1000;  
        }  

        kbytes_of_data = <?php echo $test_kbytes?>;  
        linespeed     = kbytes_of_data/downloadtime;  
        kbps          = (Math.round((linespeed*8)*10*1.024))/10;  
        nexturl = 'index.php?kbps='+ kbps;  
    //alert(kbytes_of_data);  
    document.location.href=nexturl;  
// -->  
</script>  
<center>  
</body>  
</html>  
<?php  
}  
?>



I hope this helped in some way. If any questions, please contact me using the contact page (top right of this page) and feel free to ask away!

Thursday August 16, 2007 - 2220 reads