Measuring Page Load Times

Permalink
Good day folks. Looking to get a handle on page load time and then start identifying where I can improve same. I've read that auto-nav and other blocks can be suspect.

Anyways, what I am working to do is to implement this script's code across two php blocks (from http://www.phpjabbers.com/measuring-php-page-load-time-php17-5.html... ):

//very beginning of your page  {in upper R/H php block}
$start = microtime(true);
//very end of your page  {in footer php block}
$end = microtime(true);
print "Page generated in ".round(($end - $start), 4)." seconds";
<pre class="brush: php"></pre>
// {note that I had to delete the <pre ...></pre> line as it caused an error to be tossed in the block when the page rendered}


I am finding that if I add two php blocks (one in the top right section and one in the footer in the bottom right section), splitting the code across them, that the code is not working as expected. I suspect that the var contents for the former are getting vaporized into the ethers, and not held in 'global' php var space.

Will someone knowledgeable please advise if this can be done via blocks, and if so, how? Thank you, in advance.

-Tod Wulff

TodWulff
 
JohntheFish replied on at Permalink Reply
JohntheFish
Your $start variable would need to be global so it is kept and can still be used by the time you get to the end. If doing that, also change its name to something that could not get confused with any other global variables or local variable with the same name.

http://php.net/manual/en/language.variables.scope.php...

Doing timing in blocks is not the cleanest way to do it because your blocks affect the timing.

Your original solution could work if you wrote it into your theme and output the time at the bottom of the page directly from your theme.