11

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?

7
  • 1
    have you tried setting it right in the php.ini file? Commented Apr 12, 2011 at 16:27
  • 3
    Apache's AllowOverride has nothing to do with PHP settings. Commented Apr 12, 2011 at 16:46
  • br.php.net/manual/en/configuration.changes.php try set and after get the value to check it... Commented Apr 12, 2011 at 17:13
  • 1
    I forgot to mention that I put a php_value max_execution_time 1000 in .htaccess, which is why I mentioned AllowOverride. Commented Apr 12, 2011 at 17:31
  • 2
    Are 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 to set_time_limit(1000); ? Commented Apr 13, 2011 at 0:37

3 Answers 3

7

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.

Sign up to request clarification or add additional context in comments.

Comments

6

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

4 Comments

is there a security issue modifying this directive in the Virtual Host ?
I 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.
Can you tell me what to write using the location tag ?
-2

Note: This hack only to run a particular script for a certain time.

Generally you should change php setting.

So In run time you can set

set_time_limit($seconds); // 0 for unlimited

at the beginning of a script.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.