PDA

View Full Version : Timer - Tempo de execução de um script.


dani piresk
19th June 2008, 18:17
<?php
class timer {
var $s_time;
var $inicio;
var $fim;
var $tempo;
var $scirpt;

function começa()
{
$this->s_time = microtime();
$this->s_time = explode(" ", $this->s_time);
$this->s_time = $this->s_time[1] + $this->s_time[0];
$this->inicio = $this->s_time;
}

function termina()
{
$this->s_time = microtime();
$this->s_time = explode(" ", $this->s_time);
$this->s_time = $this->s_time[1] + $this->s_time[0];
$this->fim = $this->s_time;
$this->tempo = ($this->fim - $this->inicio);
}

function script($this->script;)
{
include($this->script;);
}

function mostra()
{
echo "P&aacute;gina carregada em: ". round($this->tempo, 2) ." segundo(s).";
}
}
?>


Exemplo de uso:

<?php
include("class.timer.php");
$testando = new timer();
$testando->começa();
$testando->script("nome_do_seu_script.php");
$testando->termina();
$testando->mostra();
?>

//Bom proveito x]
//By Dani Piresk
//Dúvida, sugestões ou críticass: Favor Postar!