page loaded in xxx seconds

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
calebsg
Forum Commoner
Posts: 28
Joined: Tue Jun 18, 2002 10:41 am

page loaded in xxx seconds

Post by calebsg »

I have seen a few php sites with a little phrase down the bottom usually that says something like "Page load in 0.25 seconds" or something to that effect.

I'd like to do this on my site too so that I can see how fast my MySQL queries are executing and how fast the php page is loading:!: However I have not come across any tutorials on it. Could someone point me in the right direction?

TIA. :D
Wandrer
Forum Newbie
Posts: 21
Joined: Thu Jun 06, 2002 8:43 am

Post by Wandrer »

Code: Select all

class c_Timer {
    var $t_start = 0;
    var $t_stop = 0;
    var $t_elapsed = 0;

    function start() { $this->t_start = microtime(); }

    function stop()  { $this->t_stop  = microtime(); }

    function elapsed() {
        if ($this->t_elapsed) {
            return $this->t_elapsed;
        } else {
              $start_u = substr($this->t_start,0,10); $start_s = substr($this->t_start,11,10);
               $stop_u  = substr($this->t_stop,0,10);  $stop_s  = substr($this->t_stop,11,10);
            $start_total = doubleval($start_u) + $start_s;
               $stop_total  = doubleval($stop_u) + $stop_s;

            $this->t_elapsed = $stop_total - $start_total;
          print "<b>Benchmark: $this->t_elapsed seconds</b>";
            return $this->t_elapsed;
        &#125;
    &#125;
&#125;

Code: Select all

<class function here>
   $BenchmarkTimer = new c_Timer;
   $BenchmarkTimer->start();

   <your program here>

   $BenchmarkTimer->stop();
   $BenchmarkTimer->elapsed();
calebsg
Forum Commoner
Posts: 28
Joined: Tue Jun 18, 2002 10:41 am

Post by calebsg »

Looks good -- I'll give it a spin later.

Thanks.
Post Reply