Page 1 of 1

Tracking PHP script behavior and execution times

Posted: Tue May 13, 2003 2:01 pm
by ElPerezoso
Hi, all.

I've got a site with a ton of PHP documents on it, and I'm interested in collecting some statistics about them.

Is there any way, short of adding logging code to each document, for me to keep records of

a) how long a given script takes to execute, and
b) how many individual database queries it generates?

I'm just trying to figure out which portions of the code need to be better streamlined.

Thanks,
El Perezoso

Posted: Tue May 13, 2003 3:33 pm
by []InTeR[]
You can auto append and prepend a file that handles the exec time.

For the database query's you can use a function you speciefy in you auto append file. like funcion mysqlquery($query), that counts the query's and exec them

Good luck! :)

Posted: Wed May 14, 2003 3:28 am
by lcidw
Script execution time, or parsetime..

Create a file "parsetime.php" with the following contents..

Code: Select all

<?php

class parsetime { 
   var $start;
   var $stop;

   function start() { 
      list($usec, $sec) = explode(' ', microtime()); 
      $this->start = (float)$usec + (float)$sec; 
   }

   function stop() {
      list($usec, $sec) = explode(' ', microtime()); 
      $this->stop = (float)$usec + (float)$sec; 
      return number_format($this->stop - $this->start, 4); 
   }
} 
?>


At the top of the script, where it needs to start timing the execution, add..

Code: Select all

<?php
require("parsetime.php");
$parsetime = new parsetime();
$parsetime->start();
?>
At the end of the script, where the timing needs to stop and display the execution time..

Code: Select all

<?php= $parsetime->stop(); ?>