How to increase apache timeout directive in .htaccess?
Asked Answered
T

3

52

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.

Technical answered 9/3, 2012 at 5:53 Comment(0)
A
80

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.

Alonzoaloof answered 9/3, 2012 at 7:53 Comment(6)
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!Technical
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.Alonzoaloof
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?Tassel
@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.Alonzoaloof
@Technical 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. 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..."Assist
@Technical - ... 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).Assist
N
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!

Nudity answered 20/4, 2017 at 18:45 Comment(1)
Isn't this setting valid only in server configuration context? And it cannot be set in a vhost context seperately?Optime
H
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

Heribertoheringer answered 7/3, 2020 at 20:12 Comment(2)
it worked. thank youAsher
I used RewriteRule ^/?(.*) ws://127.0.0.1:%{ENV:WEBSOCKET_PORT}/$1 [P,L,E=noconntimeout:1,E=noabort:1]Organicism

© 2022 - 2024 — McMap. All rights reserved.