Skip to content
PHP Logo

How can the microtime function be utilized to calculate load time in PHP?

To calculate load time in PHP, the microtime function can be utilized by capturing the current time at the beginning of the script execution and then capturing the time again at the end of the script execution. The difference between these two times will give us the total load time of the script.

php
$start_time = microtime(true);

// Your PHP script code here

$end_time = microtime(true);
$total_time = $end_time - $start_time;

echo "Total load time: " . $total_time . " seconds";