PHP – Calculate script execution time

For debugging purposes, it is a good thing to be able to calculate the execution time of a script. This is exactly what this piece of code can do.

//Create a variable for start time

$time_start = microtime(true);



// SCRIPT CODE

//Create a variable for end time
$time_end = microtime(true);

//Subtract the two times to get seconds

$time = $time_end - $time_start;

 echo 'Execution time : '.$time.' seconds';

Leave a Reply

Your email address will not be published. Required fields are marked *

*