Advertisement
Aera223

latency-test-script

Apr 1st, 2020
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.90 KB | None | 0 0
  1. <?php
  2.  
  3. $t = ((1000 * microtime(true)) % 100000);
  4.  
  5. //My latency test tool. Doesn't need JavaScript. Save it as "2.php"
  6. //The initial page
  7. if($_GET['t']==""){
  8. echo '<!DOCTYPE html><html>
  9. <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>';
  10.  
  11. //Sends the frame (that will send a time-stamped request to the server. Part 2 calculates the latency from the timestamp)
  12. echo '<iframe src="2.php?t=' . $t . '" width="350em" height="70%"></iframe>';
  13. 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>
  14. <h3>How does it work?</h3>
  15. <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>
  16. <p><i>Other notes:</i><br> On Tor, expect over 600ms (can be up to 6000 at times, though 2000 is the usual max)
  17. <br><br>On the clearnet, I\'ve seen between 101ms - over 800ms (above 600 is a lil slow, while under 330 is excellent)
  18. <br>Negative latency bug was fixed a long while ago.<br>
  19. <br id="lr">Todays Results (before the above, from oldest to newest):';
  20. echo str_replace(",",", ",file_get_contents(date('d')."average.txt"));
  21.  
  22. echo'</p>
  23. <iframe id="b" src="0.php" width="1" height="1" frameborder="0"></iframe>
  24. </body></html>';}
  25.  
  26. else{
  27. $s = ((1000 * microtime(true)) % 100000);
  28. //Prevents negative latency
  29. if($latency < 0){$latency += 100000;}
  30.  
  31. //Comments on the latency, and sets the colour
  32. if ($latency < 99999){$qual = "Baaad"; $col = "f55";}
  33. if ($latency < 5000){$qual = "Slooow"; $col = "f80";}
  34. if ($latency < 3600){$qual = "Slow"; $col = "fa0";}
  35. if ($latency < 2900){$qual = "Ok-ish"; $col = "ff0";}
  36. if ($latency < 1800){$qual = "Ok"; $col = "ff6";}
  37. if ($latency < 1000){$qual = "Good"; $col = "8f0";}
  38. if ($latency < 660){$qual = "Nice"; $col = "8f8";}
  39. if($latency < 480){$qual = "Great"; $col = "5fb";}
  40. if($latency < 350){$qual = "Fast!"; $col = "0ff";}
  41.  
  42. //Shows the user their latency
  43. echo '<!DOCTYPE html><html>
  44. <style>body{background:#'.$col.';color:#000; font-family:corbel;}</style><body><p>' . $s . '</p>
  45. <h1>Latency:' . $latency. 'ms ('. $qual .')</h1>
  46. <a href="colour.php" target="blank">Test again in new tab? <mark>:)</mark></a>
  47. </body></html>';
  48.  
  49. //Records the latency, so I have an idea of how slow/fast users are.
  50.  
  51. // Makes a CSV file, so the latency can be processed with Excel, and users can see the simplified data
  52. $qq = fopen(date("j")."average.txt", "a");
  53. $oo = $latency . ",";
  54. fwrite($qq, $oo);
  55. fclose($qq);}
  56. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement