51

How do I increase the apache timeout directive in .htaccess? I have a LONG $_POST['script'] that takes a user probably 10 minutes to fill in all the data. The problem is if it takes too long than the page times out or something and it goes to a webpage is not found error page. Would increasing the apache timeout directive in .htaccess be the answer I'm looking for. I guess it's set to 300 seconds by default, but I don't know how to increase that or if that's even what I should do... Either way, how do I increase the default time? Thank you.

Graham
  • 1,433
  • 3
  • 21
  • 34

3 Answers3

79

if you have long processing server side code, I don't think it does fall into 404 as you said ("it goes to a webpage is not found error page")

Browser should report request timeout error.

You may do 2 things:

Based on CGI/Server side engine increase timeout there

PHP : http://www.php.net/manual/en/info.configuration.php#ini.max-execution-time - default is 30 seconds

In php.ini:

max_execution_time 60

Increase apache timeout - default is 300 (in version 2.4 it is 60).

In your httpd.conf (in server config or vhost config)

TimeOut 600

Note that first setting allows your PHP script to run longer, it will not interferre with network timeout.

Second setting modify maximum amount of time the server will wait for certain events before failing a request

Sorry, I'm not sure if you are using PHP as server side processing, but if you provide more info I will be more accurate.

robsch
  • 9,358
  • 9
  • 63
  • 104
rkosegi
  • 14,165
  • 5
  • 50
  • 83
  • It is PHP. I've applied `max_execution_time = 10080` to the php.ini. So far I troubleshooted it 5 times on 3 browsers with success. Would this alone allow a user to be idle on a post form page for 3 hours (10080 sec = 3 hours) before clicking submit and avoiding the webpage is not found error? Like I said I've been good so far but still don't feel 100%. Also, is the Timeout 300 changed to Timeout 10080 OK? Would that exceed the max allowed time and would this even be necessary to avoid the problem I'm experiencing. Thank you for the great answer! – Graham Mar 09 '12 at 09:32
  • 1
    As I said, your apache httpd.conf affect network related timeouts, and php.ini settings set maximum period of time for which script is allowed to run. – rkosegi Mar 09 '12 at 09:45
  • Where in the httpd.conf do we put TimeOut 600? That line does not already exist in mine. Does it go in the 'DirectoryIndex' block or the 'Directory' block or somewhere else? – covfefe Nov 09 '15 at 21:31
  • @user3004041 : Did you read link above about TimeOut directive? it goes to server config or virtualhost. Per-directory connection settings doesn't make any sense. – rkosegi Nov 10 '15 at 07:02
  • 1
    @Graham re `max_execution_time` - that is for a long running script. E.g. a large file upload. AFAIK, doesn't affect how long a user can be idle. re `Timeout 10080`. I think not a good idea - ties up more resources unnecessarily. http://httpd.apache.org/docs/2.0/mod/core.html#timeout says "timer used to be 1200 but has been lowered to 300, which is still far more than necessary..." – ToolmakerSteve Apr 17 '19 at 20:13
  • @Graham - ... To keep connected for *hours*, I've seen recommendations to periodically send a byte of data to server as long as user is on that page. So that page doesn't timeout, but if user leaves the page, they'll get timed out (if browser fails to send message to server saying no longer needs the connection). – ToolmakerSteve Apr 17 '19 at 20:20
6

Just in case this helps anyone else:

If you're going to be adding the TimeOut directive, and your website uses multiple vhosts (eg. one for port 80, one for port 443), then don't forget to add the directive to all of them!

Nate
  • 1,442
  • 14
  • 22
  • 1
    Isn't this setting valid only in server configuration context? And it cannot be set in a vhost context seperately? – robsch Feb 20 '20 at 12:52
5

This solution is for Litespeed Server (Apache as well)

Add the following code in .htaccess

RewriteRule .* - [E=noabort:1]
RewriteRule .* - [E=noconntimeout:1]

Litespeed reference

e-israel
  • 623
  • 10
  • 30