Apache logs mod_fcgid: ap_pass_brigade failed in handle_request_ipc function
mod_fcgid: ap_pass_brigade failed in handle_request_ipc functionShort answer
mod_fcgid logs this when it fails to pass the PHP response on to the client, and returns a 500. The failure usually starts on the FastCGI side, and mod_fcgid logs the real reason just before it. Read those lines: a read timeout points to FcgidIOTimeout, a closed connection to a PHP process that ended.
Fix it fast
1Find out which cause you have
Open the Apache error log and read the lines just before the ap_pass_brigade warning. mod_fcgid writes the reason it could not read from PHP first; that line tells you which cause below applies.
grep -R "ErrorLog" /etc/apache2 /etc/httpd 2>/dev/null sudo grep -n -B4 "ap_pass_brigade failed" /var/log/apache2/error.log | tail -n 402Match what you see, then jump to its fix
- 1
mod_fcgid: read data timeout in 40 seconds, then the ap_pass_brigade line, for a slow report, export or importPHP stays silent for longer than FcgidIOTimeoutFix - 2
mod_fcgid: error reading data, FastCGI server closed connection, or another read error from the FastCGI server, on a request that works when you repeat itThe PHP process ended while mod_fcgid was using itFix
- 1
What does the error look like?
mod_fcgid: ap_pass_brigade failed in handle_request_ipc functionmod_fcgid: read data timeout in 40 secondsmod_fcgid: error reading data, FastCGI server closed connection500 Internal Server Error
Cause 1 of 2
PHP stays silent for longer than FcgidIOTimeout
1Check
FcgidIOTimeout is the longest time mod_fcgid waits to read from or write to the application, and the application must start producing its response within that time. The default is 40 seconds. Compare it with how long the failing request runs, and see whether a higher value is already set.
grep -R -n -E "FcgidIOTimeout|FcgidBusyTimeout" /etc/apache2 /etc/httpd 2>/dev/null2Fix
Raise FcgidIOTimeout above the longest quiet stretch of the request, and keep FcgidBusyTimeout, the limit for a whole request, higher still. Better yet, make the script send its first output sooner.
# Apache server or virtual host configuration
FcgidIOTimeout 120
FcgidBusyTimeout 3003Verify
Reload Apache and repeat the slow request; the read timeout line no longer appears in the error log.
sudo systemctl reload apache2
sudo tail -n 20 /var/log/apache2/error.logConfirmed by httpd.apache.org
Cause 2 of 2
The PHP process ended while mod_fcgid was using it
1Check
By default a PHP FastCGI process exits after 500 requests. It can exit after mod_fcgid has already connected and sent the next request, which logs an error and returns a 500. A request that runs longer than FcgidBusyTimeout, 300 seconds by default, can be terminated as well. Look at the request limits.
grep -R -n -E "PHP_FCGI_MAX_REQUESTS|FcgidMaxRequestsPerProcess" /etc/apache2 /etc/httpd /usr/local/bin 2>/dev/null2Fix
Set PHP's request limit and mod_fcgid's limit together, with the Apache value equal or lower, so mod_fcgid retires a process before PHP does. The documentation shows a wrapper script for the PHP side. Raise FcgidBusyTimeout if a legitimate request runs past 300 seconds.
# Apache configuration
FcgidMaxRequestsPerProcess 10000
# /usr/local/bin/php-wrapper
PHP_FCGI_MAX_REQUESTS=10000
export PHP_FCGI_MAX_REQUESTS
exec /usr/local/bin/php-cgi3Verify
Restart Apache, send more requests than the old limit, and check that the closed connection line does not return.
sudo systemctl restart apache2
for i in $(seq 1 600); do curl -s -o /dev/null -w "%{http_code}\n" https://example.com/; done | sort | uniq -cConfirmed by httpd.apache.org
How do I stop it coming back?
- Pick FcgidIOTimeout from the slowest real request, not from the default, and keep FcgidBusyTimeout above it.
- Always change PHP_FCGI_MAX_REQUESTS and FcgidMaxRequestsPerProcess together, and keep the Apache value equal or lower.
- Leave PHP_FCGI_CHILDREN at 0: the mod_fcgid documentation says PHP's own child process management should always be disabled with it.
- Move long exports and imports into a background job, so no web request depends on a timeout.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Apache returns 500 with Premature end of script headers
500 Internal Server Error
Apache ran your script, but the script printed no valid HTTP header before its output.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Apache on Windows refuses to start because httpd.conf names a PHP module it cannot find
Apache service will not start after adding PHP to httpd.conf
LoadModule needs the name of the module variable inside the DLL.
3 causes, each with a fixServers
Composer reports a different PHP version than php -v on Ubuntu
You are running 8.1.2.
Composer takes its PHP version from the interpreter that runs it, unless config.platform fakes one.
3 causes, each with a fixServers
docker-php-ext-install mbstring fails: oniguruma not found
The docker-php-ext-install step exits with a non-zero code
mbstring needs the Oniguruma library to build its regex functions, and the PHP build finds it through pkg-config.
3 causes, each with a fixServers
Docker php image has no php.ini and my edits do not stay
A setting changed in php.ini inside the container is gone after the container is recreated
The official php image ships php.ini-development and php.ini-production but no active php.ini.
2 causes, each with a fix