| | |||||||
| |||||||
| |||||||
|
|
|
|
|
|
|
Well, here it is... the new, faster, safer, easier and all around better class to easily assist you in determing the time it takes to generate a php page. This code is extremely simple, yet extremely powerful. All the bugs have been ironed out and it has been streamlined and optimized to deliver the goods in an extremely easy and fast little package. The code is compatible with php 4 & 5 and is extremely easy to implement... simply, include the page, declare the class and you're good. After that, place the start() function where you want to begin timing, the stop() function where you want to end timing, and the gen() function where you want to display the time. the gen function simply returns the value, so make sure to utilize it inside of a print() or echo() command. The gen() function must also be after the stop() function, obviously. In addition, if you so wish, you are given the opportunity to change the decimal place to which the returned value is rounded too... simply modify the $change_to variable, it defaults to 4. Below is an example implementation... include_once('class.pagegen.php'); $pagegen = new page_gen(); $pagegen->round_to = 7; $pagegen->start() // all of your php code $pagegen->stop(); print('page generation time: ' . $pagegen->gen()); By : jam wil <?php class page_gen { // // PRIVATE CLASS VARIABLES // var $_start_time; var $_stop_time; var $_gen_time; // // USER DEFINED VARIABLES // var $round_to; // // CLASS CONSTRUCTOR // function page_gen() { if (!isset($this->round_to)) { $this->round_to = 4; } } // // FIGURE OUT THE TIME AT THE BEGINNING OF THE PAGE // function start() { $microstart = explode(' ',microtime()); $this->_start_time = $microstart[0] + $microstart[1]; } // // FIGURE OUT THE TIME AT THE END OF THE PAGE // function stop() { $microstop = explode(' ',microtime()); $this->_stop_time = $microstop[0] + $microstop[1]; } // // CALCULATE THE DIFFERENCE BETWEEN THE BEGINNNG AND THE END AND RETURN THE VALUE // function gen() { $this->_gen_time = round($this->_stop_time - $this->_start_time,$this->round_to); return $this->_gen_time; } } ?>
More Date Time Code Articles |
| |
| |