Skip to content

Tracking the script execution time in PHP

Last updated on December 13, 2015

Hi there guys! Today I am going to share a very useful snippet that you can use to see the execution time of your script while debugging your script.

Tracking the script execution time in PHP is very easy with below simple steps:

First you have to define variables at the start and at the ends and call the microtime() function at start and end and store the time in those variables.

After that you will need to subtract the end variable from the start variable (micro time) and that’s it. Below is the simple example.

$v) {
   echo $v;
}
 
//Create a variable and store end time
$end = microtime(true);
 
//Subtract the two times to get seconds
$time = ($end - $start);
echo 'This script executed in '. $time .' seconds';
?>

Functions

mixed microtime ([ bool $get_as_float = false ] ) — Return current Unix timestamp with microseconds

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments