Measuring PHP page load time

Put the following code at the very top of your PHP page (if you measure the time needed for particular part of the code put this right before that PHP code part)

<?php
$time = microtime();
$time = explode(‘ ‘, $time);
$time = $time[1] + $time[0];
$start = $time;
?>

The following code has to be put at the very end of the web page (or the end of the PHP code part)


<?php
$time = microtime();
$time = explode(‘ ‘, $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish – $start), 4);
echo ‘<p>Page generated in ‘.$total_time.’ seconds.</p>’.”\n”;
?>

Now, when you access your web page you will know the time needed for it to execute. This is an example output of  what you are going to see:
Page generated in 0.0031 seconds.

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

Your email address will not be published. Required fields are marked *