views:

23

answers:

2

I've got an applicaiton with various php scripts. I want to get an idea of how much time it takes for the execution to move from one point to another (there are many such points).

I was looking for a simple php line that I can insert without modification, at different spots in my code and get an output file (NOT generated html) which shows something like:

FILENAME      FUNCTION        LINENUMBER      TIMESTAMP

I've started using this:

file_put_contents('/home/default/public_html/debug.log',  __FILE__ . "\t" .
 __FUNCTION__ . "\t" . __LINE__ . "\t" . microtime(true)."\n", FILE_APPEND);

which is good, but are there better ways of doing the same?

+1  A: 

For a simple way to do this, you can either use the global PHP error system with trigger_error() and a E_NOTICE level, or the error_log() function to log in a separate file.

I your case I would recommend the second solution.


With the trigger_error():

<?php
    trigger_error("Call will start now", E_NOTICE);
    startTheHugeCall();
    trigger_error("Call is finished", E_NOTICE);
?>

With the error_log() :

<?php
    error_log("Call will start now", 3, "/var/tmp/debugfile.log");
    startTheHugeCall();
    error_log("Call is finished", 3, "/var/tmp/debugfile.log");
?>

Resources :

Colin Hebert
A: 

You could use the XDebug extension to generate raw profiling data. It will generate files in your /tmp directory by default that you can crunch using command line tools or various GUIs.

Jeff Standen