PHP Classes

PHP Timer Trait: Measure elapsed time as a trait

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 126 All time: 9,427 This week: 39Up
Version License PHP version Categories
timer-trait 1GNU General Publi...5.4PHP 5, Time and Date, Traits
Description 

Author

This package provides a trait that measures the time that elapsed between different moments of the execution of the script.

It keeps track of the time it starts measuring the elapsed time, so later it can return the time that passed since the start time.

The trait can also return the remaining time until it reaches a given moment.

Picture of Jacob Fogg
  Performance   Level  
Name: Jacob Fogg <contact>
Classes: 7 packages by
Country: United States United States
Age: 44
All time rank: 1047148 in United States United States
Week rank: 50 Up7 in United States United States Up
Innovation award
Innovation award
Nominee: 3x

Winner: 1x

Example

<?php
namespace Fogg\Util\Timer;

use
Fogg\Util\Timer\TimerTrait;

/**
 * This is a simple example class to demonstrate the functionality of
 * the TimerTrait class.
 *
 * @author Jacob Fogg
 */
class example{
    use
TimerTrait;

    public function
__construct(){
        echo
"Starting the timer and setting a limit of 5 seconds.<br>";
       
$this->timer_start();
       
$this->timer_set_limit(5);

        echo
"Sleeping for 3 seconds<br>";
       
sleep(3);

        echo
$this->timer_elapsed()." seconds have elapsed.<br>";
        echo
"There ".($this->timer_has_remaining()?'is':'is not')." time left on the timer.<br>";
        echo
$this->timer_remaining()." seconds are remaining on the timer.<br>";

        echo
"Sleeping for 3 more seconds<br>";
       
sleep(3);

        echo
$this->timer_elapsed()." seconds have elapsed.<br>";
        echo
"There ".($this->timer_has_remaining()?'is':'is not')." time left on the timer.<br>";
        echo
$this->timer_remaining()." seconds are remaining on the timer.<br>";

        echo
"Resetting the timer.<br>";
       
$this->timer_reset();

        echo
$this->timer_elapsed()." seconds have elapsed.<br>";
        echo
"There ".($this->timer_has_remaining()?'is':'is not')." time left on the timer.<br>";
        echo
$this->timer_remaining()." seconds are remaining on the timer.<br>";
    }
}


  Files folder image Files (2)  
File Role Description
Files folder imageFogg (1 directory)

  Files folder image Files (2)  /  Fogg  
File Role Description
Files folder imageUtil (1 directory)

  Files folder image Files (2)  /  Fogg  /  Util  
File Role Description
Files folder imageTimer (2 files)

  Files folder image Files (2)  /  Fogg  /  Util  /  Timer  
File Role Description
  Plain text file TimerTrait.php Class The Timer Trait Class
  Accessible without login Plain text file TraitExample.php Example A simple example class to demonstrate the functionality of the TimerTrait class.

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:126
This week:0
All time:9,427
This week:39Up