Speedtest Source |
Speedtest |
Source of:
Speedtest - Source page - Stylesheet
#!/usr/bin/php-cgi
<?php
$version = "2.5";
function timer_t()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$copyright = '<div class="border copyright"><b>© ' . date("Y") . '</b> Joakim "firetech" Andersson</div>'
?>
<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<script language="JavaScript" type="text/javascript">
<!--
if (window != top)
top.location.href = location.href;
function progress_update(pos) {
for (var p = 0; p < pos; p++) {
document.getElementById('progress'+p).style.backgroundColor = '#0000ff';
}
}
function progress_start() {
document.getElementById('message').firstChild.nodeValue = "Sending test data...";
}
function progress_end() {
progress_update(30);
document.getElementById('message').firstChild.nodeValue = "Test finished!";
}
//-->
</script>
<link rel="stylesheet" media="all" type="text/css" href="speedtest.css">
<title>Speedtest <?=$version?></title>
</head>
<body>
<table class="page"><tr>
<td align="left"><span class="title">Speedtest</span> <span class="subtitle"><?=$version?></span></td>
<td align="right"><a href="source.php">Source</a></td>
</tr></table><br>
Test will last for at least 5 seconds. Have patience.<br><br>
<script language="JavaScript" type="text/javascript">
<!--
document.write(
'<table cellpadding="5" cellspacing="0" class="contents"><tr><td><center>' +
'<b><span id="message">Preparing test...</span></b><br><br>' +
'<span class="progressbar">'
);
for (var p = 0; p < 30; p++) {
document.write('<span id="progress' + p + '"> </span>');
}
document.write(
'</span><br><br>' +
'<b><span id="size">0</span></b> kB downloaded in <b><span id="time">0</span></b> seconds.</center></td></tr>' +
'<tr><td class="speed">' +
'<center><b><span id="speed_kbits">0</span></b> kbit/s. (<b><span id="speed_kBs">0</span></b> kB/s)</center>' +
'</td></tr></table>' +
'<br><i>The first values <u>will</u> be faulty. The last value is the most correct.</i><br>' +
'<br>' +
'<?php print $copyright; ?>'
);
//-->
</script>
<?php
$data = "";
for ($i = 0; $i < 102400; $i++) {
$data .= chr(rand(1,255));
}
$total_s = 0;
$total_t = 0;
print "
<script language=\"JavaScript\" type=\"text/javascript\">
<!--
progress_start();
";
do {
print "//-->
</script>
<!--
";
$m_start_t = timer_t();
print $data;
$m_stop_t = timer_t();
$this_t = $m_stop_t - $m_start_t;
$total_s += 100;
$total_t += $this_t;
$pos = min(30, max(0, round(($total_t / 5) * 30)));
$total_v = ((8*$total_s)/$total_t);
$speed_kbits = round($total_v,2);
$speed_kBs = round(($total_v/8),2);
print "
-->
<script language=\"JavaScript\" type=\"text/javascript\">
<!--
document.getElementById('size').firstChild.nodeValue = '$total_s';
document.getElementById('time').firstChild.nodeValue = '".round($total_t,2)."';
document.getElementById('speed_kbits').firstChild.nodeValue = '$speed_kbits';
document.getElementById('speed_kBs').firstChild.nodeValue = '$speed_kBs';
".($total_t <= 5 ? "progress_update($pos);\n" : "");
} while ($total_t <= 5);
print "progress_end();
//-->
</script>
<noscript>
<table cellpadding=\"5\" cellspacing=\"0\" class=\"contents\"><tr><td><center>
<b>Test finished!</b><br><br>
<b>$total_s</b> kB downloaded in <b>".round($total_t,2)."</b> seconds.</center></td></tr>
<tr><td class=\"speed\">
<center><b>$speed_kbits</span></b> kbit/s. (<b>$speed_kBs</b> kB/s)</center>
</td></tr></table>
<br>
$copyright
</noscript>
";
?>
</body>
</html>
© 2024 Joakim "firetech" Andersson