I've often seen this and wondered how this was done. I can get a working copy from PHPNuke, but I that's wrong. I want to write my own and understand it. So will someone please enlighten me on what it takes to get a page generation time.
Page Generation Time
[man]microtime[/man] at the top and bottom of the script. Subtract the start from the end...
Put this where u want time displayed (Preferably at bottom of page)
<?php
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$time_start = getmicrotime();
for ($i=0; $i <1000; $i++)
{ }
$time_end = getmicrotime();
$time = $time_end - $time_start;
$time = round($time,4);
echo "Page loaded in $time seconds";
?>
Ok ok ok. So I've got it working, and very nicely. However I noticed it's counting the time the script took to execute, however on big sites where theres a lot to be loaded onto the clients computer, the codes stopped processing but the page is still loading. Or maybe I'm doing it wrong. Ideas?
PHP runs on the server. as such it can only tell you how long the server took to parse the script. it cannot tell you how long the data took to be transfered to the client and then how long the client took to parse the output.
Silly me. Thanks :p