PHP Classes

File: timerReadMe.txt

Recommend this page to a friend!
  Classes of Ivo Stoykov  >  timers  >  timerReadMe.txt  >  Download  
File: timerReadMe.txt
Role: ???
Content type: text/plain
Description: Explain how to use the timer class and what's in there
Class: timers
Author: By
Last change:
Date: 20 years ago
Size: 8,550 bytes
 

Contents

Class file image Download
/******************************************************************************
*    timer v1.0
*    Copyright (C) 2002 Ivo Stoykov (ivostoykov@hotmail.com)
*
*    This class was inspired by:
*        Nathan Wallace's article PHP: Hackers Paradise
*              (http://www.e-gineer.com/articles/php-hackers-paradise.phtml )
*    and
*        Allan Kent's article Timing Script Execution
*              (sorry but I've lost the url')
*
*    This script is freeware and is realeased under the GPL.
*    (see attached file GPL.txt)
*    It is distributed in the hope that it will be useful
*    but WITHOUT ANY WARRANTY.
*
*    You can redistribute it and/or modify it under the
*    terms of the license (attached as GPL.txt)
*
*    If you did not receive a copy of the GNU General Public License
*    along with this program you could obtain a copy eithrt by writing to
*    the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*    Or by downloading it from http://fsf.org/
********************************************************************************
*    This script is to measure different proceces in your web site.
*
*    You could combine it with logger class so as to be informed. (i.e. how long
*    users has stay on a particular page)
********************************************************************************/
/*
   CLASS:   timer
   PURPOSE: compute the time elapsed for a given process (i.e. showing a web page into a browser)
   FAST USAGE:
            1. include the class file - i.e. include('timer.inc');
            2. start the timer. (i.e. $the_time = new timer(); )
            3. compute the time elapsed. (i.e. print $the_time->get_elapsed_time(); )

   COMPRIHENSIVE USAGE:
            1. include the class file - i.e. include('timer.inc');
            2. start the timer using
                  $t = new timer();    // constructor for an anonimous one
               or using
                  $t = new timer('my_timer');   // to create a particular timer.

               This way (with names) you could create as many times as you need.

            3. compute the time elapsed. (i.e. print $the_time->get_elapsed_time(); )

                        print $t->get_elapsed_time('my_timer'); // this will return the time
                                                               up to this point
               3a.   If you nead to measure intermediate time passed use these functions
                     in the following order:

                        print $t->get_elapsed_time('my_timer'); // this will return the time
                                                               up to this point
                        .
                        .
                        // some action taken
                        .
                        .
                        $t->stretch_timer('my_timer'); //   this will return the time passed
                                                         from the point the timer($t) has been
                                                         created and the point this funciont
                                                         has been fired.
                  NOTE: This won't print the elapsed time. To obtaine it you should fire again
                        the function get_elapsed_time; i.e.:

                        print $t->get_elapsed_time('my_timer'); // this will return the time
                                                               up to this point

   MORE USAGE:
            1. $t->stop_timer('my_timer'); // will stop the timer without printing the result
            2. $t->get_start_time('my_timer'); // will get the starting time only
            3. $t->get_end_time('my_timer'); // will get the ending time only
            4. $t->reset_timer('my_timer'); // will reset a timer
            5. $t->reset_all_timers(); // will reset all timers at once

   FUNCTIONS LIST:
            function timer (constructor)
               PARAMETERS:    name of the timer - any valid string
               RESULT:        void

            function start_timer
               PARAMETERS:    name of the timer to start;
                              if no timer with the given name
                              one will be created.
                              If no name supplied (default)
                              an annonimous timer will be created.
               RESULT:        void

            function stop_timer
               PARAMETERS:    name of the timer to stop;
                              if no timer with the given name
                              one will be created, started and then stopped
                              (this is instead of messing your code with
                               error messages)
               RESULT:        void

            function stretch_timer
               PURPOSE:       you cannot stop twice the timer;
                              instead use this finction
                              This is included if you want to measue
                              a result in a middle point between the start
                              and the real end of the timer
               PARAMETERS:    name of the timer to stop;
                              if no timer with the given name
                              one will be created, started and then stopped
                              (this is instead of messing your code with
                               error messages)
               RESULT:        void

            function set_timer
               PURPOSE:       user internally, you do not need to call it

            function get_start_time
               PURPOSE:       this is which should be used to retrieve the
                              starting time (in UNIX miliseconds format)
               PARAMETERS:    name of the timer to start;
                              if no timer with the given name
                              one will be created. If no name supplied (default)
                              an annonimous timer will be created.
                              (this is instead of messing your code with
                               error messages)
               RESULT:        double

            function get_end_time
               PURPOSE:       this is which should be used to retrieve the
                              stoping time (in UNIX miliseconds format)
               PARAMETERS:    name of the timer to start;
                              if no timer with the given name
                              one will be created. If no name supplied (default)
                              an annonimous timer will be created.
                              (this is instead of messing your code with
                               error messages)
               RESULT:        double

            function get_elapsed_time
               PURPOSE:       this is which should be used to retrieve the
                              total time the timer has been working
               PARAMETERS:    name of the timer to start;
                              if no timer with the given name
                              one will be created. If no name supplied (default)
                              an annonimous timer will be created.
                              (this is instead of messing your code with
                               error messages)
               RESULT:        double

            function reset_timer
               PURPOSE:       this will clear the timer with the given name
               PARAMETERS:    name of the timer to start;
                              if no timer with the given name no action
                              will be taken
               RESULT:        void

            function reset_all_timers
               PURPOSE:       this will clear all existing timers.
               PARAMETERS:    void
               RESULT:        void
**************************************************************************************

   TODO:
      1. Intermediate independant markers of each timer
      2. Session implemetation
      3. Showing results of all timers together
      4. Suggest something ...

   CONTACTS:
      for suggestions, commendation, disapprobation, etc. contact me to
         ivostoykov@hotmail.com; ICQ # 13382056

Jan. 06 2002         
*/
For more information send a message to info at phpclasses dot org.