PHP Classes

File: Fogg/Util/Timer/TraitExample.php

Recommend this page to a friend!
  Classes of Jacob Fogg   PHP Timer Trait   Fogg/Util/Timer/TraitExample.php   Download  
File: Fogg/Util/Timer/TraitExample.php
Role: Example script
Content type: text/plain
Description: A simple example class to demonstrate the functionality of the TimerTrait class.
Class: PHP Timer Trait
Measure elapsed time as a trait
Author: By
Last change:
Date: 9 years ago
Size: 1,279 bytes
 

Contents

Class file image Download
<?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>";
    }
}