
|
 |

Measuring time to execute PHP scriptIf 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. 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.
|
|
|