Australia's Leading Digital Marketing Experts. T. 1300 235 433  |  Aggreagtion Enquires Welcome

Measure PHP Page Load Time

The following will measure page load time. Handy on MySQL functions, loops, APIs etc.

Place the following at the top of your page (or where you want to measure from).

1
<?php 
2
$time = microtime();
3
$time = explode(' ', $time);
4
$time = $time[1] + $time[0];
5
$start = $time;

Place the following at the bottom of your page (or where you want to measure to).

1
<?php 
2
$time = microtime();
3
$time = explode(' ', $time);
4
$time = $time[1] + $time[0];
5
$finish = $time;
6
$total_time = round(($finish - $start), 4);
7
echo 'Page generated in ' . $total_time . ' seconds.';

It makes sense to write them into functions so you can reuse them.

Like this article?

Share on facebook
Share on Facebook
Share on twitter
Share on Twitter
Share on linkedin
Share on Linkdin
Share on pinterest
Share on Pinterest

Leave a comment