Home » PHP

PHP: Display page render time

12 June 2009 2 Comments

Here’s what I currently use to determine how long it takes to generate a page in PHP. Its only 4 lines of code.

PHP 5

$time_start = microtime(true);
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "Displaying the render time: $time seconds\n";

PHP 4 Version: (8 lines)

Put this at the top of the PHP script:

$render_time_start = microtime_float();

Put this at the end of the script:

$render_time_end = microtime_float();
$render_time = $render_time_end - $render_time_start;
echo $render_time;

function microtime_float(){
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}

2 Comments »

  • Phil said:

    isnt your microtime_float function just the same as microtime(true) ?

  • admin (author) said:

    I’ve updated the script for PHP5. PHP4 didn’t have the true parameter, so thats what the float function was for. Thanks.

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.