How to calculate execution time in PHP

Snippet

To check the execution time of a piece of code you need to use the microtime() function, example:

downloadcopy
<?php
//place this before any script you want to calculate time
$time_start = microtime(true); 

//do something

$time_end = microtime(true);

// calculate execution time
$execution_time = ($time_end - $time_start);

//execution time of the script
echo 'Total Execution Time: '.number_format((float) $execution_time, 10) .' seconds';