WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Ok, so I'm confused as to what's going on here... I've been trying for hours now to get a relatively accurate page load timer setup on my WordPress site, but nothing is working like it's supposed to.

I've added this code to my theme's header.php file as the very first block of code:

  $exectime = microtime();
  $exectime = explode(" ",$exectime);
  $exectime = $exectime[1] + $exectime[0];
  $starttime = $exectime; 

and then I added this block of code as the very last thing in my theme's footer.php file:

  $exectime = microtime();
  $exectime = explode(" ",$exectime);
  $exectime = $exectime[1] + $exectime[0];
  $endtime = $exectime;
  $totaltime = ($endtime - $starttime);
  echo '<!-- page rendered in '.$totaltime.' seconds -->';

but rather than getting a somewhat accurate representation of how long it took the page to load, I'm getting these gargantuan numbers that I know aren't even close to accurate...

Here's one example result:

<!-- page rendered in 1321818086.6252 seconds -->
share|improve this question
up vote 1 down vote accepted

$starttime is undefined in your footer, so you're subtracting nothing from endtime. declare global $starttime first and it'll work.

that said, it won't be a very accurate indicator of rendering time, since most of the work WordPress does happens before you ever reach the template and start your timer. There's already a built-in timer that starts when WP is first loaded, you can print the output with the timer_stop function.

share|improve this answer
Ok, declaring $starttime as global didn't do the trick... and I was under the impression that timer_stop() was simply the time it took to execute the queries, not actually load the page... However, I think I may be confusing server processing time for front-end display time... So I guess I'll just stick with timer_stop() for now and be done with it. – Nero_DCLXVI Nov 20 '11 at 21:23
declare it as global in header before you use it. timer_stop is total execution time, queries and page rendering. no PHP-based timer will be able to start before your server responds to a request and starts up PHP, it's accurate within it's own scope of awareness, but it can't possibly account for server response times and network latency. – Milo Nov 20 '11 at 21:24
I see... I guess that's where I was getting confused. I know nothing can account for network latency, but surely there's gotta be a way to account for server response times? (even if not in php) – Nero_DCLXVI Nov 20 '11 at 21:41
@Nero_DCLXVI I use the network panel in webkit browsers to see response and load times. if it's not a local server it's always relative to my ISP and path to host, of course. – Milo Nov 21 '11 at 18:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.