Start and stop a timer PHP

Use the microtime function. The documentation includes example code.ShareImprove this answer Follow answered Nov 29 2011 at 12:13 Jon 408k7575 gold badges710710 silver badges780780 bronze badges Add a comment 131

You can use microtime and calculate the difference:

$time_pre = microtime(true);
exec(...);
$time_post = microtime(true);
$exec_time = $time_post - $time_pre;

Here’s the PHP docs for microtime: http://php.net/manual/en/function.microtime.php

Leave a Comment