How to show page execution time in PHP (One line)

Description:

There are two methods of displaying the page generation time in PHP. **Old PHP versions can do this as below:** $time_start = microtime(true); // Write your code here… $time_end = microtime(true); $gen_time = $time_end – $time_start; echo “This page has been generated in: {$gen_time} seconds.”; **As of PHP 5.4.0 you can simply measure page generation […]


There are two methods of displaying the page generation time in PHP.

**Old PHP versions can do this as below:**

$time_start = microtime(true);
// Write your code here…
$time_end = microtime(true);
$gen_time = $time_end – $time_start;
echo “This page has been generated in: {$gen_time} seconds.”;

**As of PHP 5.4.0 you can simply measure page generation time as follows (append this at the end of your php script file):**

$gen_time = microtime(true) – $_SERVER[“REQUEST_TIME_FLOAT”];
echo “This page has been generated in: {$gen_time} seconds.”;

Search on our website