phptimeloadpageload

PHP Get Page Load Stats - How to measure php script execution / load time


What I have in the header:

$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$start = $time;

What I have in the footer:

$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start), 4);
echo 'Page generated in ' . $total_time . ' seconds.';

Output: Page generated in 1292008977.54 seconds.

Can someone please help me figure out why the result is not right?? I am using PHP5.


Solution

  • microtime() returns the current Unix timestamp with microseconds. i don't see any math there that does the conversion from microseconds to seconds.

    microtime(true) returns the time as a float in seconds