TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-14-2007, 11:14 PM   #1 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,215
Thanks: 90
Wildhoney is on a distinguished road
Red face Script Execution Time Class

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.
Attached Files
File Type: zip TalkPHP_Timer.PHP4.zip (1.2 KB, 151 views)
File Type: zip TalkPHP_Timer.PHP5.zip (1.2 KB, 351 views)
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.

Last edited by Wildhoney : 09-14-2007 at 11:42 PM.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 09-14-2007, 11:25 PM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,239
Thanks: 3
Salathe is on a distinguished road
Default

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". :)
__________________
salathe@php.net
Salathe is offline  
Reply With Quote
Old 09-14-2007, 11:36 PM   #3 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,215
Thanks: 90
Wildhoney is on a distinguished road
Default

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.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 04:22 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design