Maximum execution time of 300 seconds exceeded - php

I got this error message :
And I already set this on the top of my page
// Display error - if there is
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('MAX_EXECUTION_TIME', -1);
Any suggestion ?

ini_set('max_execution_time', 0).
Don't use all caps (in general for ini settings) and use 0 not -1 when setting value to no limit.
http://php.net/manual/en/info.configuration.php#ini.max-execution-time

Related

ini_set for max_execution_time is not working

I'm using Command line of PHP with Yii Framework Command.
As I know on cli default value is 0
When I changed its value to 2 sec, it's giving 0 value that is success value as old value.
I also checked value after changing
ini_set('max_execution_time', 2);
using
echo ini_get('max_execution_time');
it's giving correct value i.e. 2
I have put tracker for getting the total execution time after that code
$scriptStartTime = time();
.....
some code
.....
echo (time() - $scriptStartTime);
It gives more than 5 sec.
Any Idea why it's not giving timeout error?

usleep reaches max limit very quickly, how to prolong

I put my code on sleep when no data returned by server. But it gives me this error after a while being idle.
<b>Fatal error</b>: Maximum execution time of 120 seconds exceeded in
I know, changing the max limit in php.ini would help. But i don't want to do this, because I don't own the server...so I can't be changing each clients server limit.
how can I set the max limit to infinity here or probably how to reconnect if reached max?
while ($currentmodif <= $lastmodif)
{
usleep(10000); // sleep 10ms to unload the CPU
clearstatcache();
$currentmodif = filemtime($filename);
}
You'll have to set it to zero. Zero means the script can run forever. Add the following at the start of your script:
ini_set('max_execution_time', 0);
set_time_limit() does not return anything so you can't use it to detect whether it succeeded. Additionally, it'll throw a warning:
Warning: set_time_limit(): Cannot set time limit in safe mode
ini_set() returns FALSE on failure and does not trigger warnings.

Proper way to set php max_execution_time

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.
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.
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.

Server gives error 500 on a loop with sleep - php

I am getting internal server error with a loop in php.
The loop basically do this:
for ($i = 1; $i <= 9; $i++) {
sleep(5);
}
it have an execution time limit set to 120 and also set the memory limit and display erros.
set_time_limit(120);
ini_set('memory_limit', '128M');
ini_set ('display_errors', 'On');
I get an 500 internal server error.
And other script in the same server stop to work while looping.
There is another Runtime Configuration In
You must change value of
max_execution_time In php.ini
usually this attribute set to 30 seconds , you can increase this to 100 seconds

PHP Max Exection Timeout Notification

Is it possible to get Max Execution timeout notification so that i can use code clean up operations before the php script stops running?
Basically, i am trying to create a script that can do some changes/modifications to my database which has huge data pile. Also, this php script execution can be paused/resumed using a filelock.
You can either use set_error_handler() or register_shutdown_function().
Edit: See also: max execution time error handling
If you set 0 to set_time_limit, it will never stop :)
You can increase the limit time inside your code using:
set_time_limit(300); //time in seconds
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
or
changing the max_execution_time parameter inside your php.ini.
The default time is 30 seconds.

Categories