Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $t = ((1000 * microtime(true)) % 100000);
- //My latency test tool. Doesn't need JavaScript. Save it as "2.php"
- //The initial page
- if($_GET['t']==""){
- echo '<!DOCTYPE html><html>
- <style>body{background:#f80;color:#008; font-family:corbel; margin-left:2em}</style><body><h2>Latency takes a moment to measure. The box changes colour when done </h2><p>If the box isn\'t present, then the test can\'t run. Timestamp 1:<br>' . $t . ' </p>';
- //Sends the frame (that will send a time-stamped request to the server. Part 2 calculates the latency from the timestamp)
- echo '<iframe src="2.php?t=' . $t . '" width="350em" height="70%"></iframe>';
- echo '<b><h3>What\'s this?</h3> <p>This is a latency test, which measures the time to connect to a site (in this case, '.$_SERVER["SERVER_NAME"].').<br> Unlike other latency tests, all measurements are on one server.</p>
- <h3>How does it work?</h3>
- <p>It measures the time between server message, and response. It will even include your PCs rendering latency (added to the total). <br>Note: Latency results are kept in files for debugging/curiousity purposes.<br></b>Fun fact: Now they are organised by day <a href="#lr">here</a></p>
- <p><i>Other notes:</i><br> On Tor, expect over 600ms (can be up to 6000 at times, though 2000 is the usual max)
- <br><br>On the clearnet, I\'ve seen between 101ms - over 800ms (above 600 is a lil slow, while under 330 is excellent)
- <br>Negative latency bug was fixed a long while ago.<br>
- <br id="lr">Todays Results (before the above, from oldest to newest):';
- echo str_replace(",",", ",file_get_contents(date('d')."average.txt"));
- echo'</p>
- <iframe id="b" src="0.php" width="1" height="1" frameborder="0"></iframe>
- </body></html>';}
- else{
- $s = ((1000 * microtime(true)) % 100000);
- //Prevents negative latency
- if($latency < 0){$latency += 100000;}
- //Comments on the latency, and sets the colour
- if ($latency < 99999){$qual = "Baaad"; $col = "f55";}
- if ($latency < 5000){$qual = "Slooow"; $col = "f80";}
- if ($latency < 3600){$qual = "Slow"; $col = "fa0";}
- if ($latency < 2900){$qual = "Ok-ish"; $col = "ff0";}
- if ($latency < 1800){$qual = "Ok"; $col = "ff6";}
- if ($latency < 1000){$qual = "Good"; $col = "8f0";}
- if ($latency < 660){$qual = "Nice"; $col = "8f8";}
- if($latency < 480){$qual = "Great"; $col = "5fb";}
- if($latency < 350){$qual = "Fast!"; $col = "0ff";}
- //Shows the user their latency
- echo '<!DOCTYPE html><html>
- <style>body{background:#'.$col.';color:#000; font-family:corbel;}</style><body><p>' . $s . '</p>
- <h1>Latency:' . $latency. 'ms ('. $qual .')</h1>
- <a href="colour.php" target="blank">Test again in new tab? <mark>:)</mark></a>
- </body></html>';
- //Records the latency, so I have an idea of how slow/fast users are.
- // Makes a CSV file, so the latency can be processed with Excel, and users can see the simplified data
- $qq = fopen(date("j")."average.txt", "a");
- $oo = $latency . ",";
- fwrite($qq, $oo);
- fclose($qq);}
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement