diff --git a/readme.md b/readme.md index df55847..4f1ea1a 100644 --- a/readme.md +++ b/readme.md @@ -3,7 +3,7 @@ Debug tools like: varExport* functions, timer, server dump, SQL Beautifier, etc. ## Prerequisite -* PHP 4 (v1.0), PHP 5.4+ (v1.1+) ou PHP 7 & 7.4 (v2) +* PHP 4 (v1.0), PHP 5.4+ (v1.1), PHP 5.6 (v1.2+) or PHP 7.4 (v2) ## Install Edit your [composer.json](https://getcomposer.org) (launch `composer update` after edit): @@ -12,7 +12,7 @@ Edit your [composer.json](https://getcomposer.org) (launch `composer update` aft "repositories": [ { "type": "git", "url": "git@github.com:jgauthi/component_debug.git" } ], - "require": { + "require-dev": { "jgauthi/component_debug": "1.*" } } diff --git a/src/timer.class.php b/src/timer.class.php new file mode 100644 index 0000000..43f7e65 --- /dev/null +++ b/src/timer.class.php @@ -0,0 +1,127 @@ + + * @maj 14/03/09 + * @version 1.0 + */ + +class timer +{ + var $debut; + var $fin; + var $time = array(); + var $start = false; + var $header = 0; + var $resultat; + var $etape; + + //-- CONSTRUCTEUR --------------------------------- + FUNCTION timer($header = 0) + { + $this -> debut = microtime(); + $this -> header = $header; + } + + //-- ETALONNER LE PARCOURS DU SCRIPT -------------- + FUNCTION etape($nom) + { + $this -> time[] = array('nom' => $nom, 'time' => microtime()); + } + + //-- METTRE FIN AU COMPTEUR + FUNCTION stop() + { + $this -> fin = microtime(); + + // Conversion + $this -> debut = $this -> _unit($this -> debut); + $this -> fin = $this -> _unit($this -> fin); + + // Vérifie si le header est correcte + if ($this -> header && headers_sent()) $this -> header = false; + + // Analyse des données + $this -> resultat = $this -> _conv($this -> fin - $this -> debut); + + // Analyse des étapes + if (count($this -> time) > 0) + { + $etape = ''; + foreach($this -> time as $id => $tmp) + { + $temp = $this -> _vir($this -> _conv($this -> _unit($tmp['time']) - $this -> debut)); + $this -> etape .= '- '.$tmp['nom'].': '.$temp." ms\n"; + if ($this -> header) + header($id.'-Time: '.$temp.' ms -> '.$tmp['nom']); + } + } + + // Renvoi des données + if ($this -> header) header('X-Time: '.$this -> _vir($this -> resultat).' ms'); + } + + //-- + FUNCTION OutPut($type = 'commentaire') + { + if ($type == 'commentaire') + { + $av = ''; + } + else + { + $av = '