Created
February 26, 2016 10:11
-
-
Save oktomus/186683ca228f3361efe1 to your computer and use it in GitHub Desktop.
Calculate the reponse time of your webpage, useful to check SQL request time.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app; | |
class Time | |
{ | |
private $startTime, $reponseTime; | |
public function __construct(){ | |
$this->startTime = microtime(true); | |
} | |
public function end(){ | |
$this->reponseTime = microtime(true) - $this->startTime; | |
$this->display(); | |
} | |
public function display(){ | |
$html = '<div style="z-index:999;position:fixed;bottom:0;right:0;padding:20px;background-color:rgba(255,0,0,.5);color:white;">'; | |
$html .= '<span>Temps de réponse : ' . ($this->reponseTime) . ' seconds</span>'; | |
$html .= '</div>'; | |
echo $html; | |
} | |
} | |
// -------------------------- | |
// HOW TO USE IT | |
// -------------------------- | |
// -------------------------- | |
// To put at the top | |
// of your php file | |
// -------------------------- | |
// If you don't have autoload | |
require_once('Time.php'); | |
// Then | |
$t = new app\Time(); | |
// -------------------------- | |
// To put at the end | |
// of your php file | |
// -------------------------- | |
$t->end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment