How can I set the maximum execution time for a PHP script?
Solution 1
Setting the variable in the ini file works for me:
max_execution_time = 1000;
set_time_limit() should work as well, as long as it's not in safe mode.
Solution 2
If you're looking for an Apache2-directive to use in .htaccess or the configuration of one VirtualHost, you probably need php_admin_value:
php_admin_value max_execution_time 1000
AFAIK this only works with mod_php
Related videos on Youtube
Nick Q.
Working with hackers to make their lives even more awesome. Currently, COO at Major League Hacking. Former Developer Evangelist at SendGrid. Unabashed nerd & computer lover. Hit me up on Twitter: @YayNickQ
Updated on July 25, 2020Comments
-
Nick Q. almost 4 years
I would like to change the maximum execution time for a PHP script. In the script I have tried
ini_set("max_execution_time", "1000");
and
set_time_limit(1000);
together and separately.
I also added this line to .htaccess:
php_value max_execution_time 1000
php.ini has safemode off and the Apache server has the flag
AllowOverride All
. What must I do to get the server to allow a longer execution time?-
Marc B about 13 yearsApache's AllowOverride has nothing to do with PHP settings.
-
Frank Farmer about 13 yearsAre you sending requests directly to apache? Proxies may time out even if apache doesn't. What do you get if you run
var_dump(ini_get('max_execution_time'), ini_get('safe_mode'));
after your call toset_time_limit(1000);
? -
Nick Q.I forgot to mention that I put a
php_value max_execution_time 1000
in.htaccess
, which is why I mentioned AllowOverride. -
Jeff Busbyhave you tried setting it right in the php.ini file?
-
-
mlwacosmos almost 7 yearsis there a security issue modifying this directive in the Virtual Host ?
-
Lukas almost 7 yearsI wouldn't think so. Basically there is a difference between php_admin_value and php_value, the latter permits ini_set() to change the value, the former doesn't. see ma.ttias.be/…. You might want to be careful about allowing long runtimes in a whole VirtualHost though. Maybe use it inside a <Location> tag to be more granular.
-
mlwacosmos almost 7 yearsCan you tell me what to write using the location tag ?
-
Lukas almost 7 yearsHave a look at httpd.apache.org/docs/current/mod/core.html#location