Friday, December 11, 2015

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)

1
2
3
4
5
6
<?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)

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

No comments:

Post a Comment