How can I check how long my exec()
script has been running for? The output would be something like this:
1 Day(s) 2 hours 23 minutes 12 seconds
I don't want it to output more then 60 seconds like this
1 Day(s) 2 hours 23 minutes 118 seconds
My code:
$start = time();
$s = time() - $start;
$m = floor($s / 60);
$h = floor($m / 60);
$msg = "script running for approx: Seconds - $s | Minutes - $m | Hours - $h";
echo $msg;
Divide the seconds part on 60 with /
you will get the exact mins add the to your mins and then divide the seconds part with %
you will get the remaining second, which are less than 60.
Edit
Even you might have problem with your mins as well. change that too
$start = time();
$s = time() - $start;
$m = floor($s / 60);
$h = floor($m / 60);
$mins = ($m % 60);
$seconds = ($s % 60);
$msg = "script running for approx: Seconds - $seconds | Minutes - $mins | Hours - $h";
echo $msg;
If using PHP 5.4, this is gives the exact amount of time spent in PHP
$runtime = round(microtime(TRUE) - $_SERVER['REQUEST_TIME_FLOAT'], 6);
echo "Script running for $runtime seconds";