W3hobbyist

Snippets and resources for PHP, MySQL, JavaScript-AJAX

Archive for the ‘PHP-MySQL’ Category

Measuring time needed for the execution of a PHP script

without comments

1

You have often seen that at the bottom of some pages:

Page generated in 0.23 sec

You too can display that by using PHP’s inbuilt microtime() function.

1
2
3
4
5
6
7
<?php
$startedAt=microtime(true);//Time at initiation of the script.
//some function such as fetching data and generating output from a database
$finishedAt=microtime(true);//Time at end of script
$timeConsumed=$finishedAt-$startedAt;
echo "$timeConsumed sec were needed for execution of the script.";
?>

Written by Rohan Shenoy

June 5th, 2008 at 3:32 pm

Posted in PHP-MySQL