You are here: Re: [PHP] unexplainable - page generation time class « PHP « IT news, forums, messages
Re: [PHP] unexplainable - page generation time class

Posted by Ian Firla on 03/06/05 10:07

I think the problem is how, when and where you're calling things.

Basically, your code is fine. I modified it slightly and get the correct
output. This could still be cleaned up and optimised significantly;
however, I think you can take it from here:

Your Class:

<?php
class page_gen {
//
// PRIVATE - DO NOT MODIFY
//
var $cls_start_time;
var $cls_stop_time;
var $cls_gen_time;

//
// FIGURE OUT THE TIME AT THE BEGINNING OF THE PAGE
//

function start() {
$microstart = explode(' ',microtime());
$this->cls_start_time = $microstart[0] + $microstart[1];
return $this->cls_start_time;
}

//
// FIGURE OUT THE TIME AT THE END OF THE PAGE
//
function stop() {
$microstop = explode(' ',microtime());
$this->cls_stop_time = $microstop[0] + $microstop[1];
return $this->cls_stop_time;
}

//
// CALCULATE THE DIFFERENCE BETWEEN THE BEGINNNG AND THE END AND
COLOR CODE THE RESULT
//
function gen($start, $stop) {
$this->cls_gen_time = $stop - $start;
return $this->cls_gen_time;
}
}
?>

index php that calls it:

<?PHP

require_once("timer.php");

$page_gen = new page_gen;

$start=$page_gen->start();
sleep(2);
$stop=$page_gen->stop();

echo("start/stop: $start $stop<br><br>");

$gentime=$page_gen->gen($start, $stop);

echo "generation time: ". $gentime;

?>

Output:

start/stop: 1110096261.12 1110096263.13

generation time: 2.00168681145

All the best,

Ian

---
Ian Firla Consulting
http://ianfirla.com

On Sat, 2005-03-05 at 22:04 -0700, James Williams wrote:
> Howdy! I've made a class which simply determines the page generation
> time of a php script... After pretty much an hour of straight examining
> the code and trying tons of different things, no good has come of it,
> however I can't find an error... anywhere.
>
> <?php
> class page_gen {
> //
> // PRIVATE - DO NOT MODIFY
> //
> var $cls_start_time;
> var $cls_stop_time;
> var $cls_gen_time;
>
> //
> // FIGURE OUT THE TIME AT THE BEGINNING OF THE PAGE
> //
> function start() {
> $microstart = explode(' ',microtime());
> $this->cls_start_time = $microstart[0] + $microstart[1];
> }
>
> //
> // FIGURE OUT THE TIME AT THE END OF THE PAGE
> //
> function stop() {
> $microstop = explode(' ',microtime());
> $this->cls_stop_time = $microstop[0] + $microstop[1];
> }
>
> //
> // CALCULATE THE DIFFERENCE BETWEEN THE BEGINNNG AND THE END AND
> COLOR CODE THE RESULT
> //
> function gen() {
> $this->cls_gen_time = $this->cls_stop_time -
> $this->cls_start_time;
> return $this->cls_gen_time;
> }
> }
> ?>
>
> What happens is it simply returns the $this->cls_start_time variable.
>
> Both the start() and stop() functions work fine because to test them I
> put print commands at the end and they both returned proper results, the
> error appears to be in the line where I minus the start time from the
> end time. It simply returns a negative start time instead of minusing
> the two.
>
> I tried changing the minus to a plus for testing sake and it just took
> out the negative. Does anybody have any idea what is going on here?
> Thanks-you
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация