Spiga

php page generation time

by Gabi Solomon

After a few tinkering i wrote this bit of code that i use on almost all my websites to determine the page generation time. It's relatively simple but it does the job. you just call the function once at the begining of the script and once at the end .... end voila :) .

PHP:
  1. function script_generation ( $round = 7 ) {
  2. if ( isset( $GLOBALS['script_start_time'] ) ) {
  3. list($usec, $sec) = explode(" ", microtime());
  4. return round(($usec + $sec) - $GLOBALS['script_start_time'], $round);
  5. } else {
  6. list($usec, $sec) = explode(" ", microtime());
  7. $GLOBALS['script_start_time'] = $usec + $sec;
  8. }
  9. }// FUNCTION USAGE
  10. script_generation();
  11. usleep(100);
  12. $gen_time=script_generation ( 5 );
  13. echo "This script took $time seconds to generate";

Related Posts