Page loading time in PHP
This code calculates the time it takes to interpret and run the PHP code.
$startTime = array_sum(explode(' ', microtime()));
The time that the code starts is recorded. This is done by calling microtime
which returns 2 parts (the current time in seconds and milliseconds), for better accuracy we sum both parts.
//you code here
Insert the script here that will be timed.
$endTime = array_sum(explode(' ', microtime()));
echo 'This page took approximately '.round($endTime - $startTime, 7).'seconds to load.';
Finally the time after the code has been interpreted is stored and the difference between start time and end time is printed to the user.