Advertisement
TDamiao

Teste de conexão

Feb 20th, 2018
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.    Teste de velocidade de conexão
  3.    Por: TDmaiao
  4.  
  5. */
  6.  
  7. <div id="transferencia" />
  8.  
  9.  
  10. <?php
  11.  
  12. $kbs = 10000;
  13.  
  14. if(isset($_GET['teste'])) {
  15.     echo str_repeat("x", 1024 * $kbs) ;
  16. }
  17.  
  18. else {
  19.  
  20.  
  21. ?>
  22.  
  23. <script>
  24.  
  25. var finalizou   = 0;
  26. var inicializou = 0;
  27. var velocidade  = 0;
  28.  
  29.  
  30. xmlhttp= (window.XMLHttpRequest)? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
  31.  
  32. xmlhttp.onreadystatechange = function()
  33. {
  34.     if (xmlhttp.readyState==4 && xmlhttp.status== 200)
  35.     {
  36.        finalizou = new Date().getTime();
  37.  
  38.        velocidade = (<?php echo $kbs * 1000; ?>/(finalizou  - inicializou)) >> 0;
  39.  
  40.        document.getElementById("transferencia").innerHTML = ("Taxa de download: <b>" +velocidade+" kbps</b>");
  41.      
  42.  
  43.     }
  44. }
  45.  
  46. iniciarTeste = function() {
  47.  
  48.     document.getElementById("transferencia").innerHTML = "<br/><img src=\"http://www.steinhaus.com.br/images/aguarde2.gif\" />";
  49.    
  50.     inicializou = new Date().getTime();
  51.     xmlhttp.open("GET","testecliente.php?teste",true);
  52.     xmlhttp.send();
  53.    
  54.     return true;
  55. }
  56.  
  57. iniciarTeste();
  58.  
  59. </script>
  60.  
  61. <?php
  62.  
  63. }
  64.  
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement