Upload Share and Earn

Saturday, August 18, 2007

PHP Script Execution Time

You may have seen this feature of some sites around the net. Time execution basically means you can see how long it took for the page to load. This can be helpful when programming, or whenever.
An example of this script:Script Execution Time: 0.001 seconds
Lets say you have a basic HTML page: Just some text Just some text Just some text Just some text Just some text Just some text Just some text Just some text Just some text Just some text Just some text Just some text Just some text Just some text Just some text
So we'll add the time execution script here.
The basic logic behind this is we need to see at what time the script started, and when it ended. After that we just need to find the difference between those two numbers.
To refresh your memory on how time and dates on the internet work, please check out, Playing with Dates.
Instead of using the common mktime() function to get the current timestamp, we'll use the following function to get the micro time. This is because usual execution times are much less then 1 second, so we'll need to use this for more accurate times.
The function we will be using to get the current micro time is this:




?>

That's about it, now you can see how long it takes to load the page.

No comments:

 
eXTReMe Tracker