Page Generation Timer
Original posted by: Admin on 01-03-2007
Have you ever visited one of those sites that has a small statement down the bottom that says. 'Page Generated in 0.03 Seconds'. Lots of different websites
use them, even Google has a little timer.
This is quiet an easy application to write. You simply need to find the time the page started processing data, and minus it from the time it stopped processing data.
The microtime function is perfect for this.
//Create the class
class generation {
//Start variable
var $start_time;
//Constructor
function generation() {
//Define start time
$this->start_time = microtime(true);
}
function stop() {
//Return time
return microtime(true) - $this->start_time;
}
}
When you call your global config file you should initialize the class.
$gen = new generation();
Make sure this is the first thing you do so that you can get a true representation of how long it took the server to generate your page.
Then at the bottom of your page you should call the stop function which will tell you how many seconds it took to generate your page.
echo 'Page generated in '.$gen->stop().' seconds';