Reputation: 1045
i try to set my execution time in php
, but seems like it doesn't work.
I have tried this.
<?php
function secondsToTime($s)
{
$h = floor($s / 3600);
$s -= $h * 3600;
$m = floor($s / 60);
$s -= $m * 60;
return $h.':'.sprintf('%02d', $m).':'.sprintf('%02d', $s);
}
$a = microtime(true);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
ini_set('max_execution_time', 3);
sleep(2);
echo 'oke';
sleep(3);
echo 'yes';
$b = microtime(true);
echo secondsToTime($b-$a);
?>
But when i try, it shows 11 seconds, instead of error or something.
why does my code doesn't error?? i set time to 6 secs. but my whole process is 11 secs??
Do i need to define it on my php.ini
too?
Thank you.
Upvotes: 0
Views: 573
Reputation: 1829
it's show me this Error
Fatal error: Maximum execution time of 6 seconds exceeded
You doesn't get this error because on your server "Display Error" is not on.
Do i need to define it on my php.ini too ?
No need to define it on php.ini too.you can set this dynamically like you already had.
Upvotes: 1
Reputation: 6661
set_time_limit
sets the maximum execution time in seconds. If set to zero, no time limit is imposed
set_time_limit(0);
By default, the maximum execution time for PHP scripts is set to 30 seconds. If a script runs for longer than 30 seconds, PHP stops the script and reports an error. You can control the amount of time PHP allows scripts to run by changing the max_execution_time directive in your php.ini file.
Upvotes: 1