PHP Classes

Execution Time Tracker: Keep track of the time PHP scripts take to execute

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: 329 All time: 7,155 This week: 455Up
Version License PHP version Categories
runtimelogger 1.0.0Free for non-comm...5.0PHP 5, Time and Date, Performance and...
Description 

Author

This class can keep track of the time PHP scripts take to execute.

It gets the time in microseconds at each given moment the class is called adding milestones associated to optional text labels.

At the end it returns an array with the times the elapsed between each milestone.

Picture of Md. Shahadat Hossain Khan Razon
  Performance   Level  
Name: Md. Shahadat Hossain ... <contact>
Classes: 14 packages by
Country: Bangladesh Bangladesh
Age: 43
All time rank: 2986 in Bangladesh Bangladesh
Week rank: 44 Up1 in Bangladesh Bangladesh Up

Example

<?php

ini_set
('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include_once
'RunTimeLogger.php';

class
A{
    public
$timer;
    function
__construct(){
       
$this->timer=new RunTimeLogger();
    }
    public function
runAnyMethod(){
       
$this->timer->milestone(__METHOD__.'.start');
        try{
           
sleep(10);
        }catch (
Exception $e){
           
$this->timer->milestone(__METHOD__.'.sleepfail');
        }
       
$this->timer->milestone(__METHOD__.'.end');
    }
}

$timer=new RunTimeLogger(4, false);
$obj=new A();
## any other script
for($i=0; $i<99999999; $i++) $j='any task!';
$timer('loopdone');
$timer1=new RunTimeLogger(false);
$timer2=new RunTimeLogger('simple timer of shahadat');
$obj->runAnyMethod();
echo
'$obj->runAnyMethod() log: '.$timer('anymethodrundone').'<br />';
echo
'just echo last log: '.$timer.'<br />';
for(
$i=0; $i<999; $i++) $j='another task!';
$timer('task2done');
echo
'<h3>now lets see log!</h3>
        <h5>global timer</h5><pre>'
.print_r($timer(true), true).'</pre>
        <h5>class timer</h5><pre>'
.print_r($obj->timer->get(true), true).'</pre>
        <h5>timer that didnot started</h5><pre>'
.print_r($timer1(true), true).'</pre>
                <p>end of log</p>'
;




  Files folder image Files (2)  
File Role Description
Plain text file RunTimeLogger.php Class RunTimeLogger Class
Accessible without login Plain text file eg1.php Example RunTimeLogger Example

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:329
This week:0
All time:7,155
This week:455Up
User Comments (1)
bad bad bad coding
9 years ago (Menahem Begin)
2%Star