Page load/script execution time
Use the following code at or near the beginning of your page/script:
<?php
function getmicrotime(){
list($usec,$sec)=explode(" ",microtime());
return ((float)$usec+(float)$sec);
}
$time_start=getmicrotime();
?>
And then this at or near the end:
<?php
$time_taken=round(getmicrotime()-$time_start,4);
echo"Generated in ".$time_taken." seconds";
?>
The code will generate an output such as this:
Generated in 0.1234 seconds
Great stuff, i can see this helping lots of new members to the forum in bulding their sites and stuff, i know it will help a few of my mates so i wanna say thanks for sending it in as i may even need it myself one day :) but who knows.
Good idea. It relaly helps to find out how lenghty is your page and how long it takes to load. I will surely use them on my site
mtajim;59:
Good idea. It relaly helps to find out how lenghty is your page and how long it takes to load. I will surely use them on my site
More accurately it measures how much time the server spends performing the script and creating the final output such as HTML. You'd need interaction with the client side to figure out how long it takes a person to actually download the output from the server to their computer.
stalemate
202.***.***.***
I am so glad that I finally got the code I was looking.This has solved my problem.I will surely use them in my site.
penguinmama
66.***.***.***
Is it possible to explain how this works? I see that there's a bit at the beginning, and another bit at the end of the script - but since the function is called, wouldn't it be just measuring the time of *that function* and not of the script/page?
Unless I misunderstood your question;
No, because functions are processed on a case by case basis as they are called, they do not process by themselves where they are written and then keep a state to return to the calls.
penguinmama
12.***.***.***
Right, that's what I mean. So the script is happily running along, the function is called, it measures the time it runs, then the script continues... right? I don't understand how it can measure the entire time, if it is a function. I'm confused :)
Dismounted
59.***.***.***
Me as a PHP coder, I like to have code clearly spaced :).
<?php
function getmicrotime()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time_start = getmicrotime();
?>
And the other;
<?php
$time_taken = round(getmicrotime() - $time_start, 4);
echo ("Generated in " . $time_taken . " seconds.");
?>