I have a script where I have set:
set_time_limit(0)
but still get
Fatal error: Maximum execution time of 90 seconds exceeded in /home/Feed.php on line 234
I've also tried setting:
php_value max_execution_time 120
in the .htaccess file but still can't stop this error - any ideas why this is not overriding?
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.
The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php. ini . When called, set_time_limit() restarts the timeout counter from zero.
To increase the script execution time, you can use the following snippet at the top of your script. ini_set ( 'max_execution_time' , '300' ); In the above example, it would set the max_execution_time directive to 300 seconds.
Most likely, your host is running a copy of PHP with the Suhoshin patch installed. This patch provides a large number of security and operational enhancements to PHP, including allowing the host to disable functions like set_time_limit()
.
There are other ways a host could disable the set_time_limit()
function, but that's the most likely. (especially as you've already ruled out Safe Mode)
Why would they disable this function? Because a PHP function that takes a long time to run also typically takes a lot of server resources; in a shared hosting environment, it is wise for the host to mitigate this kind of thing to avoid having a rogue script impact other users.
What can you do about it?
Firstly, are you sure you need to set the time limit? Do you know why your script takes that much time to run? Can you work around it? Perhaps doing a bit of profiling on your code might help you find the bottlenecks and speed up the program.
Alternatively, if you really do need to set the time limit, you may need to ask your host to enable you to do so, or else upgrade your package or switch hosting providers.
This function has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the php.ini
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With