WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : A Timing Class
Categories : PHP, PHP Classes, Date Time Click here to Update Your Picture
Ben Barnett
Date : Jun 07th 2004
Grade : 1 of 5 (graded 3 times)
Viewed : 6181
File : 3906.php
Images : No Images for this code example.
Search : More code by Ben Barnett
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

This class starts a timer on instantiation. You can then stop it whenever you want by calling the timer::timer_stop() function. Show the time between instantiation and stopping by calling timer::timer_show() function.

Both stopping and showing the timer is done by the timer::timer_stop_show() function. This gives you the time including milliseconds to 3 decimal places, but you can pass timer_show() and timer_stop_show() functions a number of decimal places to display instead.

Timer Class

@author Ben Barnett <ludge@spymac.com>
@version 1.1

Timing Class
When a new object is created, it immediately starts timing and only stops when
you call objectname->endtimer(). The calculations for finding time taken are not carried
out until they are ready to be displayed to avoid them effecting the timer results. Although I
doubt they'd make much difference.


<?php
class timer
{
/**
* The start time of the timer
*/
var $starttime;

/**
* The end time of the timer
*/
var $endtime;


/**
* Constructor begins timer.
*/
function timer()
    {
   
$this->starttime = microtime();
    }

/**
* Stops the timer.
*/
function timer_stop()
    {
   
$this->endtime = microtime();
    }

/**
* Calculates and returns the time taken.
*
* Explodes the start and end time into arrays then totals up each array. Subtracts
* the start time from the end time to give time taken to the number of decimal places
* passed as a parameter.
*
* @param integer $decimals The number of decimal places to show in the timer. Default is 3.
* @return float The time taken between instantiating the class and stopping the timer.
*/
function timer_show($decimals=3)
    {
   
// Make sure the parameter is an integer
   
$decimals = intval($decimals);
   
   
// Restrict decimal places to 8
   
if($decimals > 8)
        {
       
$decimals = 8;
        }
   
// Decimal places cannot be below zero!
   
if($decimals < 0)
        {
       
$decimals = 0;
        }
   
   
// Explode into arrays so that the decimal and UNIX timestamp can be added
   
$starttime = explode(" ", $this->starttime);
   
$endtime = explode(" ", $this->endtime);
   
   
// Add the decimal to the timestamp
   
$starttime = (float)$starttime[1] + (float)$starttime[0];
   
$endtime = (float)$endtime[1] + (float)$endtime[0];
   
    return
number_format($endtime - $starttime, $decimals);
    }
   
/**
* Stop and show the timer.
*
* Combines the stop and show timer functions.
*
* @param integer $decimals The number of decimal places to show in the timer. Default is 3.
* @return float The time taken between instantiating the class and stopping the timer.
*/
function timer_stop_show($decimals=3)
    {
   
$this->timer_stop();
    return
$this->timer_show($decimals);
    }
}
?>



pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes
Open and Close your website in fixed times .
Categories : PHP, PHP Classes, Cron, Date Time
Example of using the pcCalendar class, article 1468 on weberdev.com. Calendar example.
Categories : PHP, Date Time, PHP Classes, Calendar
A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function.
Categories : PHP, PHP Classes, Calendar, Date Time
Validator - A PHP class that can can be used for validating Email IDs and Dates
Categories : PHP, PHP Classes, Data Validation, Email, Date Time
A time measuring and performance benchmarking class
Categories : PHP, PHP Classes, Testing, Debugging, Date Time
Bs_StopWatch is a class to measure time intervals in microseconds.
Categories : PHP, Date Time, PHP Classes
Customizable Calendar Class
Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar
Code Execution Time Calculator
Categories : PHP, PHP Classes, Date Time
a class that uses microtime() to provide easy calculation of elapsed times
Categories : Date Time, PHP, PHP Classes
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
Authorize.net AIM Interface Class v1.0.0
Categories : PHP, PHP Classes, Ecommerce, Payment Gateways
News management class
Categories : PHP, PHP Classes, Beginner Guides
The class to check load time of your script VERY usefull for relatively slow applications, but not only..
Categories : PHP, PHP Classes, Debugging
Expose - PHP template engine, supports server and client-sided caching,a plugin system, multiple languages, template script language is based on PHP itself.
Categories : PHP, PHP Classes, Templates, Complete Programs