Measuring time needed for the execution of a PHP script
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."; ?> |