Timing PHP execution

Discussion in 'PHP' started by Cobnut, Jan 23, 2008.

  1. #1
    I'm having an execution time problem and recall a friend mentioning some tool that analyses your PHP and reports on timings for each bit, effectively showing you where all the time is being sucked up.

    Does this ring any bells with anyone? Any tools known of out there to do this?

    Any help appreciated.

    Jon
     
    Cobnut, Jan 23, 2008 IP
  2. norfstar

    norfstar Peon

    Messages:
    1,154
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm not sure about an external tool, but I've been using the following code (I didn't write it myself, it came from somewhere and I've forgotten where so unfortunately can't give credit):

    
    function getmicrotime(){ 
    	list($usec, $sec) = explode(' ',microtime()); 
    	return ((float)$usec + (float)$sec); 
    }
    
    $start = getmicrotime();
    
    // Code to be executed
    
    echo 'Execution time was '.round(getmicrotime() - $start, 4).' seconds.';
    Code (markup):
    Instead of echoing, the information could be stored in a text file, stored in a database, or emailed to you.
     
    norfstar, Jan 23, 2008 IP
  3. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #3
    I use similar code to that above and echo the results using html comments like this:

    <!-- execution time -->
    HTML:
    Brew
     
    Brewster, Jan 23, 2008 IP
  4. redvok

    redvok Active Member

    Messages:
    237
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    58
    #4
    For such things there are tools called Stress tools, you can find one most populare is Apache JMeter - jakarta.apache.org/jmeter/
     
    redvok, Jan 23, 2008 IP