Skip to content

Instantly share code, notes, and snippets.

@oktomus
Created February 26, 2016 10:11
Show Gist options
  • Save oktomus/186683ca228f3361efe1 to your computer and use it in GitHub Desktop.
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.
<?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