Show page loading time in footer?
-
Hi folks!
I tried to put some php-code into the header and footer to calculate and print the loading time of a page.
On the first line of the header.php, I inserted
<?php $pageload_start = getmicrotime(); ?>
where getmicrotime() is a funtion that returns the seconds and microseconds as a float and is created in the functions.php of the template.
In the footer.php, I inserted the following code:
<php $pageload_end = getmicrotime(); $pageload_time = round($pageload_end - $pageload_start,3); echo $pageload_time; ?>
The problem is:
Only the value of $pageload_end will be remembered, it seems as if $pageload_start never existed! So, the time printed is actually the time when $pageload_end was defined and not the loading time.I know this must be a php feature, so I tried to set $pageload_start as a global variable:
<?php $pageload_start = getmicrotime(); global $pageload_start; ?>
Didn’t work, eiter.
What am I missing?Remember: I am quite a php newbie. ??
Thanks in advance!
- The topic ‘Show page loading time in footer?’ is closed to new replies.