PHP debug time response server


/ Published in: PHP
Save to your folder(s)

How to replace sleep(2), for your PHP code. Ideal testing hosting/dns ping.


Copy this code and paste it in your HTML
  1. <?
  2. session_name('debugtime');
  3.  
  4. if( !empty($_GET['clear']) ){
  5. $_SESSION['tiempos'] = 0;
  6. $_SESSION['tiempos_veces'] = 0;
  7. header('location: '.$_SERVER['PHP_SELF']);
  8. }
  9.  
  10. $m = microtime();
  11.  
  12.  
  13. sleep(2); // Code eval
  14.  
  15.  
  16. $comienzo = explode(" ", $m);
  17. $final = explode(" ", microtime()); $tiempo = ($final[1] + $final[0]) - ($comienzo[1] - $comienzo[0]);
  18.  
  19. echo 'This time generation ', number_format($tiempo,2), ' seconds';
  20.  
  21. $_SESSION['tiempos'] = $tiempo + (empty($_SESSION['tiempos'] )?0:$_SESSION['tiempos']);
  22. $_SESSION['tiempos_veces'] = empty($_SESSION['tiempos_veces'])?1:1+$_SESSION['tiempos_veces'];
  23.  
  24. ?><br />
  25. Count refresh: <?=$_SESSION['tiempos_veces'];?><br />
  26. Average time: <?=number_format($_SESSION['tiempos']/$_SESSION['tiempos_veces'],2);?> seconds.
  27. <br />
  28. <br />
  29. <hr />
  30. <a href="<?=$_SERVER['PHP_SELF'];?>?clear=1">Restar testing time</a>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.