Display page load time

You may want to display the time it took to load a page.
Following is a set of simple PHP code which would help you achieve this goal.

Place the following snippet at the very top of your page.
(Ultimately, it’s advisable to have a header file and a footer file that are included on every page of your website).

$timer_start = str_replace(" ","",microtime());

Then place the following code at the very end of your footer.

$timer_end = str_replace(" ","",microtime());
$timer_diff = number_format($timer_end-$timer_start,6,'.','');
if($timer_diff<0) $timer_diff = "0.00";
echo "<div id='load-time' style='font-family: verdana; font-size: 8pt; color: #444444; text-align: center'>Page load time: <b>$timer_diff</b> second</div>";

Obviously, we’re assuming here that this code should be within .php files, with the current server configuration allowing for parsing of such files.

One Response to “Display page load time”

  1. Rahul says:

    Thanks! It works like a charm.

Leave a Reply