Skip to content


Page Load Time Calculation in PHP

This sections will contains code regarding different PHP & MySQL features and contains help about php/mysql issues.

Page Load Time Calculation in PHP

Postby php developer » January 28th, 2009, 9:08 am

Calculation page load time in PHP is a very simple task. First you have to save the time at the very beginning of the page and at the very end of the page. Then just subtract the them to find out the page load time.

A simple working php example is as follows which used microtime( ) php function to get the current system time in microseconds.

Start of Page:
Code: Select all
   @list($iMicroSeconds, $iSeconds) = @explode(" ", @microtime( ));
   $iPageStartTime = ((float)$iMicroSeconds + (float)$iSeconds);


End of Page:
Code: Select all
   @list($iMicroSeconds, $iSeconds) = @explode(" ", @microtime( ));
   $iPageEndTime = ((float)$iMicroSeconds + (float)$iSeconds);


Now you can display the page load time as follows:
Code: Select all
   $fPageLoadTime = @round(($iPageEndTime - $iPageStartTime), 3);

       print "Page Load Time = $fPageLoadTime Seconds";
User avatar
php developer
 
Posts: 53
Joined: July 25th, 2008, 4:56 am

Return to Board index

Return to PHP / MySQL / XML

Who is online

Users browsing this forum: No registered users and 0 guests