Site Loading Time

I was coding a web page which is over 600 lines of PHP codes. I was wondering how many seconds the server would take to load the web page. Because there are lot of control structures and loops to be executed.

How I achieved the need simply is described below.

Add the following code snippet to the PHP file(the line before the <html> tag starts).

$startTime = microtime();
$startArray = explode(" ", $startTime);
$startTime = $startArray[1] + $startArray[0];

Add the following code snippet to the PHP file(as soon the </html> tag was closed).

$endTime = microtime();
$endArray = explode(" ", $endTime);
$endTime = $endArray[1] + $endArray[0];
$totalTimeTaken = $endTime - $startTime;
$totalTimeTaken = round($totalTimeTaken,10);
echo "Load Time: ";
printf ("%f\n", $totalTimeTaken);

The method is simple what it does is store the time in micro seconds and get the difference when the <html> tag is printed and the </html> tag is printed. The differnence is the time required to load the page. Actually the correct word is  “Total Time taken to render the page”

Stupid and Simple.

Advertisements

Please add your valuable idea below, will make a discussion, thanks !

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s