header
 
     
 
pixel
pixel pixel

Measuring time to execute PHP script

If I'm ever wondering how long my PHP scripts take to execute, I add this code to the start of my pages:
<?php
function getTime()
    {
    
$a explode (' ',microtime());
    return(double) 
$a[0] + $a[1];
    }
$Start getTime();
?>
Then I add this to the end of my script:
<?php
$End 
getTime();
echo 
"Time taken = ".number_format(($End $Start),2)." secs";
?>
Sometimes it's good to get hard figures on how long your script takes to execute, particularly with complex MySQL queries. If your script is particularly tardy and you want to find out where the blockage occurs, you could also try moving the $Start or $End lines to different parts of the script to measure the execution speed of each section.

Unhelpful Helpful
Comments
Comment by sadaf on 2009-05-15
i have a question. how much maximum time should a script take to execute?

Comment by Calamaster on 2010-03-10
In response to your question: It depends how long the script is. Check your PHP.INI file for Max-execute time to make sure your script does not exceed it, or the page will time out.

Comment by discount Michael Jordan Shoes on 2010-09-17
Air Jordan Shoes are always so attractive, good quality can ensure the wearer's feet, not only that, the Michael Jordan Shoes has become a fashion, many young people are very fanatical Air Jordan. High price so many people can realize their dreams. Well now, our products directly from third-party products, so we can provide cheap Jordan Basketball Shoes and New Jordan Shoes, high quality, excellent service, come on, give yourself a choice. We offerAir Jordan 1, Air Jordan 2, Air Jordan 3,Air Jordan 4, Air Jordan 5, Air Jordan 6, Air Jordan 7, Air Jordan 8, Air Jordan 9, Air Jordan 10, Air Jordan 11 and so on!

Post a Comment
Name
Email
(optional)
Comment
RatingUnhelpful Helpful
Security Image* (this is just to prevent spam submissions)
Security Image