All of us have seen "
Page Load Time: 0.327 sec." at the bottom / footer in some web sites. This is not required for the right functioning of the web site, but gives good idea what performance we can expect from this web site and web server when the traffic grow up.
To measure the time need to process / load on web page, we will function to get absolute time on start of
PHP parsing and absolute time when this parsing will end. Next we will calculate the difference between end time and start time and the result is time need for processing the page.
To measure this time we will use
PHP microtime() function.
PHP microtime() function returns the current Unix timestamp in microseconds. The function returns the string "msec sec" where sec is the current time measured in the number of seconds since the Unix Epoch (0:00:00 January 1, 1970 GMT), and msec is the microseconds part. Both portions of the string are returned in units of seconds.
We will define
PHP function which parse
microtime() result and return complete float result. This result later easily can be used to make difference between end and start time.
And now this is complete PHP web page with sample code doing something which can measured and displayed after
"Page Load Time:".
You can try changing the size of array, the action with array within
while() operator or just to run the script on different web-servers to check how performance reflect on script execution time.
Also you can see other
PHP related tutorials here.
posted on 2010-Jan-19 | 02:36:49 AM
posted on 2010-Jan-19 | 06:59:42 AM