Tracking PHP script behavior and execution times

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
ElPerezoso
Forum Newbie
Posts: 2
Joined: Fri Apr 25, 2003 7:25 pm

Tracking PHP script behavior and execution times

Post 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
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post 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! :)
lcidw
Forum Commoner
Posts: 58
Joined: Mon Apr 28, 2003 8:55 am
Location: Netherlands

Post 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(); ?>
Post Reply