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);
}









isnt your microtime_float function just the same as microtime(true) ?
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!
Most Viewed
Categories
Blogroll
Tags
Categories
Recent Posts
Recent Comments