| « St Albans Carol Services | Integrating PHPLIST into Magento » |
mod_fcgid, timeouts, and downloads
Or,
(104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
(104)Connection reset by peer: mod_fcgid: ap_pass_brigade failed in handle_request_ipc function
And
mod_fcgid: read data timeout in 40 seconds
There's not a lot around that is helpful about these errors, so after having to try to sort them out myself, here's a report on what I've found. It's got to be worth telling you, I was up til 1am.
Summary
FcgidBusyTimeout (old name BusyTimeout) is the setting that governs the first error. Set to default and a download initiated by php will timeout after about 450 seconds, giving:
(104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server (104)Connection reset by peer: mod_fcgid: ap_pass_brigade failed in handle_request_ipc function
I think that "about 450 seconds" is a combination of 300 seconds for the FcgidBusyTimeout setting, and 120 seconds for the FcgidBusyScanInterval, and some fudge time ![]()
Only people with slow download speeds / downloading large files will force this error.
FcgidIOTimeout (old name IPCCommTimeout) governs the read data timeout error. A php script that waits for something to happen (like a download to finish) will timeout after 40 seconds when this is at its default setting, giving:
mod_fcgid: read data timeout in 40 seconds Premature end of script headers: scriptname.php
Solution
FcgidBusyTimeout 3600
# or whatever big number you want
# 3600 (seconds) allows an hour for a download
#
FcgidIOTimeout 600
# or whatever
# 600 seconds allows 10 minutes for a script to wait
# you just need to adjust it to suit the scripts you run
Where?
In this section, in httpd.conf, before the virtual hosts:
<IfModule mod_fcgid.c> FcgidBusyTimeout 3600 FcgidIOTimeout 600 # other Fcgid directives... </IfModule>
Alternatively, if you're running CPanel+WHM, use the include editor: Service Config > Apache Config > Include Editor > Pre Virtual Host Include
More Detail
Here's an annotated selection of mod_fcgid settings for httpd.conf:
<IfModule mod_fcgid.c> # Set a maximum number of requests a process will handle,
# then it'll die # this is just to keep memory cleaned up # somewhere I've read that a php process will die after 500,
# whatever you set here # but you need to set 500 here as well! FcgidMaxRequestsPerProcess 500 # # These two govern how many processes are created, # but I'm using defaults so I've commented them out # FcgidMaxProcesses 6 # FcgidMaxProcessesPerClass 6 # # What's the least number of processes for a class? # not sure what a 'class' is, but set this zero # to enable processes to be killed off FcgidMinProcessesPerClass 0 # # Now some idle settings # # Scan interval, fairly straight forward – how often it checks FcgidIdleScanInterval 30 # # How long should a process be idle for before we kill it? FcgidIdleTimeout 300 # # How old do you want processes to get? # Once they get to this number, they'll be killed once they're # idle, regardless of FcgidIdleTimeout # its another way of doing what FcgidMaxRequestsPerProcess does, # but with time instead of requests FcgidProcessLifeTime 3600 # # What about a process waiting for a connection to be made? FcgidConnectTimeout 100 # # And this is a timer for a script that has connected, # but is waiting for input/output to happen, # like a script waiting for an upload FcgidIOTimeout 600 # # a FastCGI application will be killed after handling
# a request for FcgidBusyTimeout # This is the one that kills long downloads # - the download is busy, but waiting, so it times-out FcgidBusyTimeout 3600 # # This is self-explanatory, the interval that 'busy' is checked FcgidBusyScanInterval 120 # # And last, but not least, the size of requests that can be made # needs to be bigger than any upload you want to do FcgidMaxRequestLen 100000000 </IfModule>