Go Back   CodingForums.com > :: Server side development > PHP > Post a PHP snippet

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-15-2007, 10:57 AM   PM User | #1
neel_basu
New Coder

 
Join Date: Apr 2007
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
neel_basu is an unknown quantity at this point
Broadband Speed Testing

PHP Code:
<?php 
if(isset($_GET['kbps'])) 

?> 
<?php 
        $kbps 
round($_GET['kbps'], 2); 
        
$ksec round($kbps 82); 
        
$mbps round($kbps 10242); 
        
$msec round($mbps 82); 
?> 
<center> 

<br><br> 
Your Current Bandwidth is:<br><br> 
<?php 
   
if ($mbps 1
    { 
      
printf ("%.2f",$mbps); 
      echo 
" Mbps<br><br>"
    } 
   else 
    { 
          
printf ("%.2f",$kbps); 
      echo 
"kbps<br><br>"
    } 
   echo 
"That Means You Can Download At " $ksec " KB/sec. FROM&nbsp;THIS&nbsp;SITE."
?> 
<br><br> 
<a href="spd.php">Perform a New Test</a> 
</center> 
<?php 

else 

?> 

<?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 = 'spd.php?kbps='+ kbps; 
    //alert(kbytes_of_data); 
    document.location.href=nexturl; 
// --> 
</script> 
<center> 
</body> 
</html> 
<?php 

?>

=========================================================
== DONT TEST ON LOCALHOST UPLOAD THIS FILE AND THE BINARY FILE ==
== TO A SERVER AND THEN TEST IT ==
== IT WOULD BE GOOD IF YOU USE A BINARY FILE THATS MORE THAN 2 MB==
==========================================================
Online Demo On http://www.indoservices.org/skillbound/spd.php
__________________
Zigmoyd Php Library / Extension -> http://www.zigmoyd.net Making Webdevelopment Childs Play
Hi I wanna be your friend You can add me on msn messenger neel_basu_2005@msn.com
neel_basu is offline   Reply With Quote
Old 11-09-2009, 07:42 PM   PM User | #2
buggy
New Coder

 
Join Date: Jun 2008
Posts: 57
Thanks: 15
Thanked 1 Time in 1 Post
buggy has a little shameless behaviour in the past
Works great in ie, but in Firefox while its downloading it shows this:
Code:
†€!{^w?+ӍB€q€h?�-’'\B#9m†Z<% Wšš‚“Qӥ'+~B8g$€bAa} vE‰‚,…ˆ:Kp”|Mtw„OO˜’?\zyFb.‡IM%,pp`Q „)jv—'^Jk=t.K><#o– #ZW_-Ž…JUa™_dBEذ‚`0"\ةI„)DGuDQqҮ <)@Ļ1J[œZZ^~ذFTd9šŸ*]˜H/6Wxzƒ’r$d8ǨN“o$hŽ…)N›—yv/ver‚gs^sŠŸR ™v›=hHȻ=a}b)g‡žh„iœˆrd‚ECˆYvХ~ƒ‰ Nv!?5fl0v?ŽyŽ@(#(/'9"gyA˜\gt!Šno‡q!šu?Ϥ‘*g4{{– -jžkŸnμ%Œ˜P3€оŸ{Cccu ‹s@WB+0{ !*-Hƾc (y„=L7u<]p‰(ŒƒM94W&�~NbŒ|*^m"$0:\?R r ™„r-rŠ~te~jsYh™7g…’’Qm^_FϹ]MT oܡ~Ÿ͍(+ŒŸ‹‹{g™5_ϣJmy†8,GXa ]'<ˆx‘wx#›c˜$[‚ _*— ƒarˆAAHb…IkqY;t8“ž*J)j"{"b›l"[v^A~y>:ߢR[uP‹u/4ΪE!(dФ”4JƒŸiײ];.6aœX@(IŸ€™eqpzg̳| }7 D_m9k›8ŸCOމYj()A”cHGPeBu5"Y_ -…„,—f5v ›‰ji'w{�g%ʪ…-?ƒYt4{/.Or$VA[ Š<!RŸoŽPzxq'PjXs .6Œ{pc~XE€ŸìçŒɪ!”3 HgU1X�s”#$ *jeXŸ&5B]‘x3ߵl�rw1ɶ^‡„€*i™k26Ỷ:p)?„ +‡z Šc[e.(٤‹)œ 8^'pkX-’†G�AݯӲx/aU�R:)uŽ>qt‰TEŒ,——œŒ›—{™TEmu^^L3FŒCUlN`2K3–f8@cKn@Q—Mc@3)—oIMŠ”-np”p$€-„oL™ruQxs]@WhN3}4  r&mu& `A'$l•lclXui‘"I}…h|Š/%r|’ͧ…nœf€O~@ Ÿ`|
buggy is offline   Reply With Quote
Old 08-18-2011, 06:40 AM   PM User | #3
jbh5000
New Coder

 
Join Date: Aug 2011
Location: Louisville, KY
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
jbh5000 is an unknown quantity at this point
Does this code still work?
jbh5000 is offline   Reply With Quote
Old 08-18-2011, 01:33 PM   PM User | #4
kbluhm
Senior Coder

 
kbluhm's Avatar
 
Join Date: Apr 2007
Location: Philadelphia, PA, USA
Posts: 1,502
Thanks: 2
Thanked 258 Times in 254 Posts
kbluhm will become famous soon enough
Quote:
Originally Posted by jbh5000 View Post
Does this code still work?
Did you attempt to test it for yourself before reviving a nearly 2 year old topic? If so, you made no indication.
__________________
ZCE
kbluhm is offline   Reply With Quote
Old 08-20-2011, 05:37 AM   PM User | #5
jbh5000
New Coder

 
Join Date: Aug 2011
Location: Louisville, KY
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
jbh5000 is an unknown quantity at this point
I agree 100% with you. I saw the thread was old and was being lazy instead of just testing for myself.

I did not test and should have before asking, I am sorry I am new here and just looking to learn a few things.

In the future I will make sure to try things and then ask better questions.
jbh5000 is offline   Reply With Quote
Old 08-30-2011, 04:47 PM   PM User | #6
devonssmart
New Coder

 
Join Date: Jul 2011
Location: Texas
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
devonssmart is an unknown quantity at this point
I just tried it, and it still works. Here the result :

Your Current Bandwidth is:

2048.00 Mbps

That Means You Can Download At 262144 KB/sec. FROM THIS SITE.
__________________
GPS Reviews or GPS Reviews
devonssmart is offline   Reply With Quote
Old 08-31-2011, 06:14 AM   PM User | #7
jbh5000
New Coder

 
Join Date: Aug 2011
Location: Louisville, KY
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
jbh5000 is an unknown quantity at this point
It worked for me too!

3321.00 Mbps
__________________
Mortgage Rates | Florida Mortgage Rates
jbh5000 is offline   Reply With Quote
Old 08-31-2011, 03:39 PM   PM User | #8
Rowsdower!
Senior Coder

 
Rowsdower!'s Avatar
 
Join Date: Oct 2008
Location: Some say it's everything.
Posts: 2,007
Thanks: 5
Thanked 395 Times in 388 Posts
Rowsdower! has a spectacular aura aboutRowsdower! has a spectacular aura aboutRowsdower! has a spectacular aura about
If anyone is interested, I fixed some of the calculations and made an updated version of this script, incorporating AJAX for the download speed test:

PHP Code:
<?php
#####################################################################################################
#    Note: I realize that KB and KiB have a commonly misunderstood formulation and I realize that    #
#    I am using "KB" and "MB" where I am truly calculating "KiB" and "MiB," respectively. Since        #
#    most people are used to seeing this information presented incorrectly, I am keeping that        #
#    tradition. If you prefer to see actual "KB" and "MB" ratings, just alter the $divisor variable    #
#    below to make the adjustment.                                                                    #
#####################################################################################################
$data_file "dilbert.zip";    // $data_file should be some generic binary file - this script was tested with a 3 MB zip file of some Dilbert comic strips. The file should be sufficiently large so that the latency from the initial HTTP request itself does not skew the results by much.
$filesize filesize($data_file);
$divisor 1024//set this to 1000 instead of 1024 if you want true KB and MB, rather than mis-labeled KiB and MiB that we are most used to seeing...
if(isset($_GET['ajax'])){
    
// if it's an ajax call we just read and print the binary file's contents...
    
$fd fopen ($data_file"rb+");
    
$contents fread ($fd$filesize);
    
ob_start(print $contents);
    
ob_end_flush();
    
fclose ($fd);
    exit(
0);
}
else{
    
// if this visit is not an AJAX request we display the page itself...
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Bandwidth Test</title>
<script type="text/javascript">
//<!--
var time;
var starttime;
var endtime;
var downloadtime;
var kbps;
var ksec;
var mbps;
var msec;
var ajax_run = new XMLHttpRequest();
function addCommas(nStr){
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}
function ajax_bandwidth_test(){
    cancel_any_pending_ajax();
    disable_table();
    send_ajax_call();
}
function cancel_any_pending_ajax(){
    if(ajax_run.readyState){
        if (ajax_run.readyState != 0 && ajax_run.readyState != 4){
            ajax_run.abort();
        }
    }
}
function disable_table(){
    var action_row = document.getElementById('action_row');
    var spans = action_row.getElementsByTagName('span');
    var link = action_row.getElementsByTagName('a')[0];
    link.style.zIndex = -1;
    if (spans.length>1){
        spans[1].className = 'disabled';
        spans[2].className = 'disabled';
    }
    var status_box = document.getElementById('status');
    status_box.innerHTML = "Testing Your Current Bandwidth...";
    document.title = "Bandwidth Test | Running...";
}
function send_ajax_call(){
    var result = '';
    var x = new Date();
    x = x.getTime();
    var url = '<?php print $_SERVER['REQUEST_URI']; ?>?ajax='+x;  //you will need to change the "?" to a "&" if your URI already has some $_GET variables in it... I haven't built in an automatic fix for that...
    if (window.XMLHttpRequest){
        // code for IE7+, Firefox, Chrome, Opera, Safari
        ajax_run = new XMLHttpRequest();
    }
    else{
        // code for IE6, IE5
        ajax_run = new ActiveXObject("Microsoft.XMLHTTP");
    }
    ajax_run.onreadystatechange = function(){
        if (ajax_run.readyState==4 && ajax_run.status==200){
            result = ajax_run.responseBody;    //ie won't work with responseText, but responseBody will work just fine...
            if (result!=''){
                //no point in printing the binary result to the page, just update the speed test results...
                update_results();
            }
            else{
                alert('Speed test failed!');
            }
        }
        else if (ajax_run.readyState==1){
            //connected to server, start the timer...
            time = new Date();
            starttime = time.getTime();
            document.getElementById('status').innerHTML = "Testing Your Current Bandwidth... Connected..."
        }
        else if (ajax_run.readyState==2){
            //server is processing the request...
            document.getElementById('status').innerHTML = "Testing Your Current Bandwidth... Loading..."
        }
        else if (ajax_run.readyState==4 && ajax_run.status!=200){
            alert('Speed test failed! (' + ajax_run.status + ')');
        }
    }
    ajax_run.open("GET",url,true);
    ajax_run.send();
}
function update_results(){
    time = new Date();
    endtime = time.getTime();
    if (endtime == starttime){
        downloadtime = 0;
    }
    else{
        downloadtime = (endtime - starttime)/1000;
    }
    kbytes_of_data = <?php print $filesize/$divisor?>;
    mbytes_of_data = <?php print $filesize/$divisor/$divisor?>;
    ksec = kbytes_of_data / downloadtime;
    msec = mbytes_of_data / downloadtime;
    kbps = addCommas(Math.round(ksec * 8192)/1000);
    mbps = addCommas(Math.round(msec * 8192)/1000);
    ksec = addCommas(Math.round(ksec*100)/100);
    msec = addCommas(Math.round(msec*100)/100);
    var action_row = document.getElementById('action_row');
    var cells = action_row.getElementsByTagName('td');
    var link = document.getElementById('trigger');
    var title = "Bandwidth Test | ";
    var text = '';
    if (msec>1){
        cells[1].innerHTML = "<span>" + mbps + " mbps</span>";
        cells[2].innerHTML = "<span>" + msec + " MB/s</span>";
        title += msec + " MB/s";
        text += addCommas(Math.round(mbytes_of_data*100)/100) + ' MB of data transferred in ' + downloadtime + ' seconds...';
    }
    else{
        cells[1].innerHTML = "<span>" + kbps + " kbps</span>";
        cells[2].innerHTML = "<span>" + ksec + " KB/s</span>";
        title += ksec + " KB/s";
        text += addCommas(Math.round(kbytes_of_data*100)/100) + ' KB of data transferred in ' + downloadtime + ' seconds...';
    }
    document.title = title;
    document.getElementById('status').innerHTML = text;
    link.style.zIndex = 1;
}
//-->
</script>
<style type="text/css">
*{margin:0;padding:0;}
body{padding:20px;background:#fff;}
table{border-collapse:collapse;position:relative;z-index:0;}
th,td{border:1px solid #000;cursor:default;}
th{padding:2px 5px;font-weight:bold;text-align:center;font-size:16px;}
td{width:120px;text-align:right;}
td span{padding:2px 5px;display:block;line-height:20px;}
td:first-child{width:110px;text-align:left;}
th:first-child{border-top:0;border-left:0;}
a{text-decoration:none;font-weight:bold;font-family:tahoma;font-size:12px;display:block;color:#333;padding:5px;text-align:center;position:relative;z-index:1;}
a:hover{background-color:#333;color:#fff;}
a,a:hover,a:focus,a:active{outline:0;}
#link_box{position:relative;}
#link_mask{display:block;width:100%;height:100%;background:transparent;position:absolute;top:0;left:0;z-index:0;padding:0;line-height:24px;font-size:500px;overflow:hidden;cursor:default;}
#status{margin-top:20px;}
.disabled{background-color:#333;color:#fff;}
.disclaimer td{border-right:0;border-bottom:0;border-left:0;font-size:11px;text-align:right;color:#333;width:auto;}
.disclaimer td em{font-weight:normal;font-style:italic;}
</style>
</head>
<body>
<table>
  <thead>
    <tr>
      <th>&nbsp;</th>
      <th>bits</th>
      <th>Bytes</th>
    </tr>
  </thead>
  <tbody>
    <tr id="action_row">
      <td><div id="link_box"><a href="javascript:ajax_bandwidth_test();" id="trigger">Test Bandwidth</a><span id="link_mask">&nbsp;</span></div></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr class="disclaimer">
      <td colspan="3">[ <em>speeds are only relative to your connection speed with this website</em> ]</td>
    </tr>
  </tbody>
</table>
<p id="status"></p>
</body>
</html>
<?php
}
?>
I am hosting it here for now with a 456KB file to test with (if anyone wants to see the script in action):
http://rowsdower.freehostia.com/php/?page=speed_test

Freehostia won't let me put up a file greater than 500KB in size on their free service so the current file will have to do on that sample page. In your production, however, it would be best to use a larger file (I would guess about 2MB or 3MB for a good balance of accuracy and script performance time).
__________________
The object of opening the mind, as of opening the mouth, is to shut it again on something solid. G.K. Chesterton
See Mediocrity in its Infancy
It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
Seek and you shall find... basically:
validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

Last edited by Rowsdower!; 08-31-2011 at 04:13 PM.. Reason: cleaning up code...
Rowsdower! is offline   Reply With Quote
Old 09-12-2011, 07:24 PM   PM User | #9
mustafizrana
New to the CF scene

 
Join Date: Sep 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
mustafizrana is an unknown quantity at this point
Quote:
Originally Posted by Rowsdower! View Post
If anyone is interested, I fixed some of the calculations and made an updated version of this script, incorporating AJAX for the download speed test:

PHP Code:
<?php
#####################################################################################################
#    Note: I realize that KB and KiB have a commonly misunderstood formulation and I realize that    #
#    I am using "KB" and "MB" where I am truly calculating "KiB" and "MiB," respectively. Since        #
#    most people are used to seeing this information presented incorrectly, I am keeping that        #
#    tradition. If you prefer to see actual "KB" and "MB" ratings, just alter the $divisor variable    #
#    below to make the adjustment.                                                                    #
#####################################################################################################
$data_file "dilbert.zip";    // $data_file should be some generic binary file - this script was tested with a 3 MB zip file of some Dilbert comic strips. The file should be sufficiently large so that the latency from the initial HTTP request itself does not skew the results by much.
$filesize filesize($data_file);
$divisor 1024//set this to 1000 instead of 1024 if you want true KB and MB, rather than mis-labeled KiB and MiB that we are most used to seeing...
if(isset($_GET['ajax'])){
    
// if it's an ajax call we just read and print the binary file's contents...
    
$fd fopen ($data_file"rb+");
    
$contents fread ($fd$filesize);
    
ob_start(print $contents);
    
ob_end_flush();
    
fclose ($fd);
    exit(
0);
}
else{
    
// if this visit is not an AJAX request we display the page itself...
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Bandwidth Test</title>
<script type="text/javascript">
//<!--
var time;
var starttime;
var endtime;
var downloadtime;
var kbps;
var ksec;
var mbps;
var msec;
var ajax_run = new XMLHttpRequest();
function addCommas(nStr){
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}
function ajax_bandwidth_test(){
    cancel_any_pending_ajax();
    disable_table();
    send_ajax_call();
}
function cancel_any_pending_ajax(){
    if(ajax_run.readyState){
        if (ajax_run.readyState != 0 && ajax_run.readyState != 4){
            ajax_run.abort();
        }
    }
}
function disable_table(){
    var action_row = document.getElementById('action_row');
    var spans = action_row.getElementsByTagName('span');
    var link = action_row.getElementsByTagName('a')[0];
    link.style.zIndex = -1;
    if (spans.length>1){
        spans[1].className = 'disabled';
        spans[2].className = 'disabled';
    }
    var status_box = document.getElementById('status');
    status_box.innerHTML = "Testing Your Current Bandwidth...";
    document.title = "Bandwidth Test | Running...";
}
function send_ajax_call(){
    var result = '';
    var x = new Date();
    x = x.getTime();
    var url = '<?php print $_SERVER['REQUEST_URI']; ?>?ajax='+x;  //you will need to change the "?" to a "&" if your URI already has some $_GET variables in it... I haven't built in an automatic fix for that...
    if (window.XMLHttpRequest){
        // code for IE7+, Firefox, Chrome, Opera, Safari
        ajax_run = new XMLHttpRequest();
    }
    else{
        // code for IE6, IE5
        ajax_run = new ActiveXObject("Microsoft.XMLHTTP");
    }
    ajax_run.onreadystatechange = function(){
        if (ajax_run.readyState==4 && ajax_run.status==200){
            result = ajax_run.responseBody;    //ie won't work with responseText, but responseBody will work just fine...
            if (result!=''){
                //no point in printing the binary result to the page, just update the speed test results...
                update_results();
            }
            else{
                alert('Speed test failed!');
            }
        }
        else if (ajax_run.readyState==1){
            //connected to server, start the timer...
            time = new Date();
            starttime = time.getTime();
            document.getElementById('status').innerHTML = "Testing Your Current Bandwidth... Connected..."
        }
        else if (ajax_run.readyState==2){
            //server is processing the request...
            document.getElementById('status').innerHTML = "Testing Your Current Bandwidth... Loading..."
        }
        else if (ajax_run.readyState==4 && ajax_run.status!=200){
            alert('Speed test failed! (' + ajax_run.status + ')');
        }
    }
    ajax_run.open("GET",url,true);
    ajax_run.send();
}
function update_results(){
    time = new Date();
    endtime = time.getTime();
    if (endtime == starttime){
        downloadtime = 0;
    }
    else{
        downloadtime = (endtime - starttime)/1000;
    }
    kbytes_of_data = <?php print $filesize/$divisor?>;
    mbytes_of_data = <?php print $filesize/$divisor/$divisor?>;
    ksec = kbytes_of_data / downloadtime;
    msec = mbytes_of_data / downloadtime;
    kbps = addCommas(Math.round(ksec * 8192)/1000);
    mbps = addCommas(Math.round(msec * 8192)/1000);
    ksec = addCommas(Math.round(ksec*100)/100);
    msec = addCommas(Math.round(msec*100)/100);
    var action_row = document.getElementById('action_row');
    var cells = action_row.getElementsByTagName('td');
    var link = document.getElementById('trigger');
    var title = "Bandwidth Test | ";
    var text = '';
    if (msec>1){
        cells[1].innerHTML = "<span>" + mbps + " mbps</span>";
        cells[2].innerHTML = "<span>" + msec + " MB/s</span>";
        title += msec + " MB/s";
        text += addCommas(Math.round(mbytes_of_data*100)/100) + ' MB of data transferred in ' + downloadtime + ' seconds...';
    }
    else{
        cells[1].innerHTML = "<span>" + kbps + " kbps</span>";
        cells[2].innerHTML = "<span>" + ksec + " KB/s</span>";
        title += ksec + " KB/s";
        text += addCommas(Math.round(kbytes_of_data*100)/100) + ' KB of data transferred in ' + downloadtime + ' seconds...';
    }
    document.title = title;
    document.getElementById('status').innerHTML = text;
    link.style.zIndex = 1;
}
//-->
</script>
<style type="text/css">
*{margin:0;padding:0;}
body{padding:20px;background:#fff;}
table{border-collapse:collapse;position:relative;z-index:0;}
th,td{border:1px solid #000;cursor:default;}
th{padding:2px 5px;font-weight:bold;text-align:center;font-size:16px;}
td{width:120px;text-align:right;}
td span{padding:2px 5px;display:block;line-height:20px;}
td:first-child{width:110px;text-align:left;}
th:first-child{border-top:0;border-left:0;}
a{text-decoration:none;font-weight:bold;font-family:tahoma;font-size:12px;display:block;color:#333;padding:5px;text-align:center;position:relative;z-index:1;}
a:hover{background-color:#333;color:#fff;}
a,a:hover,a:focus,a:active{outline:0;}
#link_box{position:relative;}
#link_mask{display:block;width:100%;height:100%;background:transparent;position:absolute;top:0;left:0;z-index:0;padding:0;line-height:24px;font-size:500px;overflow:hidden;cursor:default;}
#status{margin-top:20px;}
.disabled{background-color:#333;color:#fff;}
.disclaimer td{border-right:0;border-bottom:0;border-left:0;font-size:11px;text-align:right;color:#333;width:auto;}
.disclaimer td em{font-weight:normal;font-style:italic;}
</style>
</head>
<body>
<table>
  <thead>
    <tr>
      <th>&nbsp;</th>
      <th>bits</th>
      <th>Bytes</th>
    </tr>
  </thead>
  <tbody>
    <tr id="action_row">
      <td><div id="link_box"><a href="javascript:ajax_bandwidth_test();" id="trigger">Test Bandwidth</a><span id="link_mask">&nbsp;</span></div></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr class="disclaimer">
      <td colspan="3">[ <em>speeds are only relative to your connection speed with this website</em> ]</td>
    </tr>
  </tbody>
</table>
<p id="status"></p>
</body>
</html>
<?php
}
?>
I am hosting it here for now with a 456KB file to test with (if anyone wants to see the script in action):
http://rowsdower.freehostia.com/php/?page=speed_test

Freehostia won't let me put up a file greater than 500KB in size on their free service so the current file will have to do on that sample page. In your production, however, it would be best to use a larger file (I would guess about 2MB or 3MB for a good balance of accuracy and script performance time).
Matter of thinking.
mustafizrana is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:59 PM.


Advertisement
Log in to turn off these ads.