PHP Script Load Time Snippet

Use this snippet to find out if your site is taking too long, and if it is, fix it.

Insert this code snippet inside the <head> and </head> tags of your document:

$starttime = microtime();
$startarray = explode(" ", $starttime);
$starttime = $startarray[1] + $startarray[0];

Insert this code snippet directly before the closing </body> tag of your document:

$endtime = microtime();
$endarray = explode(" ", $endtime);
$endtime = $endarray[1] + $endarray[0];
$totaltime = $endtime - $starttime;
$totaltime = round($totaltime,10);
echo "Seconds To Load: ";
printf ("%f\n", $totaltime);

Result will be :-
Seconds To Load: x.xxxxxx


Read previous post:
Double vs Triple Equals

The == and === operators don't seem to make any difference; in fact, you might not have even heard of...

Close