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.