TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Script Giveaway (http://www.talkphp.com/script-giveaway/)
-   -   Script Execution Time Class (http://www.talkphp.com/script-giveaway/1125-script-execution-time-class.html)

Wildhoney 09-14-2007 11:14 PM

Script Execution Time Class
 
2 Attachment(s)
This script will calculate the execution time of your PHP scripts. The features are as follows:
  • Automatic Calculation of the Execution Time;
  • Notification upon Unexpectedly Long Execution Time;
  • Available in both PHP4 and PHP5 Flavours;
  • Set the Output's Precision.

The index.php bundled with the script contains the instructions on how to use it. The file also contains example code which can be removed. All you need to calculate and output the execution time is:

1 - Include (SSI) the execution time class to your page:

PHP Code:

include_once('./lib/TalkPHP_Timer.class.php'); 

2 - Call the start function to begin the timing:

PHP Code:

$pTimer->start(); 

3 - Call the end function to end the timing:

PHP Code:

$pTimer->stop(); 

4 - Output the total execution time using the display function:

PHP Code:

echo $pTimer->display(); 

The rest of the code contained in index.php can be removed as it is only there for test purposes. Once you have downloaded the file, open up TalkPHPTimer.class.php and replace your e-mail address with the default e-mail address in the TPHP_TIMER_ADDRESS constant. The constants used in the script are:
  • TPHP_TIMER_ADDRESS - The e-mail address to send a warning to when the execution time exceeds the specified as set in the TPHP_TIMER_EXCESSIVE constant;
  • TPHP_TIMER_EXCESSIVE - The amount of seconds that the execution time must not exceed. If it does, an e-mail will be sent to the administrator's email as specified in the TPHP_TIMER_ADDRESS constant.
  • TPHP_TIMER_PRECISION - How many numbers that should appear after the decimal when returning the execution time. Setting it to 0 means no rounding what-so-ever.

Article: For the TalkPHP article on execution times, please see this page.

Salathe 09-14-2007 11:25 PM

For the PHP5 version: as of PHP 5.0.0 there is a single, optional argument for microtime which is get_as_float (bool). Using this argument would allow you to make your start/stop functions "one liners". :)

Wildhoney 09-14-2007 11:36 PM

Updated. I do assume you meant like that. I noticed the optional argument but I didn't actually check PHP.net to understand it further. Thanks for pointing it out.


All times are GMT. The time now is 12:44 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0