httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Trawick <>
Subject Fwd: [users@httpd] mod_proxy doesn't persist connections to php-fpm
Date Thu, 14 Nov 2013 21:29:17 GMT
Need a way to stop setting backend->close without breaking other users.

FastCGI-specific keyword parameter?  envvar?

---------- Forwarded message ----------
From: Jeff Trawick <>
Date: Thu, Nov 14, 2013 at 4:26 PM
Subject: Re: [users@httpd] mod_proxy doesn't persist connections to php-fpm
To: "" <>

On Thu, Nov 14, 2013 at 4:12 PM, Chandler, Dean A <
> wrote:

>  Hi,
>                 I am trying to run Apache 2.4 web server using mod_proxy
> and proxy_fcgi to proxy php requests to the PHP-FPM running on same
> machine.  I am pretty much using default setup for php-fpm.ini with port at
> 9000.  My problem is that mod_proxy is closing the connection after every
> request is complete so I end up with 1000’s of sockets in TIME_WAIT and
> eventually apache quits creating sockets. I am using the following proxy
> statement to send requests to the php-fpm process.

Funny...  I sent this long explanation to somebody recently with a
suggestion on what to try:

mod_proxy_fcgi should share mod_proxy's general ability to pool connections
to a backend, but there has always been line of code in mod_proxy_fcgi that
marks all connections for closure at the end of the request.  I just found
the commit from 7 years ago that does it:

That line has subsequently moved around a little and the field changed; it
looks like this now:

    /* XXX Setting close to 0 is a great way to end up with
     *     timeouts at this point, since we lack good ways to manage the
     *     back end fastcgi processes.  This should be revisited when we
     *     have a better story on that part of things. */
    backend->close = 1;

I think the point of the commit message is that:

* typically you have small connection capacity in the FastCGI application
* typically your Apache configuration has a number of Apache child
processes handling client requests

In this typical scenario you can easily have a number of connections to the
FastCGI application which are ready to be reused but they are owned by
specific Apache child processes and the Apache child handling a request may
not be the one that already has the connection, and the FastCGI app may not
accept more connections until some of the other ones are closed.  (I.e.,
the new request waits for some timeout in the app which allows it to close
an existing connection and accept a new one).

If you have configured Apache with a very small number of child processes
and YOUR-BACKEND has good connection capacity (i.e., will accept many
concurrent connections), you could try commenting out that line
"backend->close = 1" in the bit of code shown above and see how it works
for you.  (Don't comment out every occurrence of "backend->close = 1",
since the backend connection should be closed after certain types of

Assuming that it works fine, check with netstat to see if the typical
number of connections to YOUR-BACKEND decreased any.

Reusing the same connections is only effective with a relatively small
number of Apache child processes.  (I guess you are using Event or Worker

> <LocationMatch ^/(.*\.php(/.*)?)$ >
>        ProxyPass fcgi://$1 ttl=300000
> keepalive=On connectiontimeout=300 ttl=300 max=128
> </LocationMatch>
> Below is log file showing connections
> [Wed Nov 13 11:42:56.176124 2013] [proxy:debug] [pid 225428:tid
> 139934623480576] proxy_util.c(2194): [client] AH00947:
> connected /home/httpbld/htdocs/status.html/status to
> [Wed Nov 13 11:42:56.176159 2013] [proxy:trace2] [pid 225428:tid
> 139934623480576] proxy_util.c(2446): FCGI: fam 2 socket created to connect
> to
> [Wed Nov 13 11:42:56.176985 2013] [proxy_fcgi:trace4] [pid 225428:tid
> 139934623480576] util_script.c(521): [client] Headers
> from script 'status':
> [Wed Nov 13 11:42:56.177038 2013] [proxy_fcgi:trace4] [pid 225428:tid
> 139934623480576] util_script.c(522): [client]
> X-Powered-By: PHP/5.5.5
> [Wed Nov 13 11:42:56.177060 2013] [proxy_fcgi:trace4] [pid 225428:tid
> 139934623480576] util_script.c(522): [client]
> Expires: Thu, 01 Jan 1970 00:00:00 GMT
> [Wed Nov 13 11:42:56.177071 2013] [proxy_fcgi:trace4] [pid 225428:tid
> 139934623480576] util_script.c(522): [client]
> Cache-Control: no-cache, no-store, must-revalidate, max-age=0
> [Wed Nov 13 11:42:56.177082 2013] [proxy_fcgi:trace4] [pid 225428:tid
> 139934623480576] util_script.c(522): [client]
> Content-Type: text/plain
> [Wed Nov 13 11:42:56.177196 2013] [proxy:debug] [pid 225428:tid
> 139934623480576] proxy_util.c(2035): AH00943: FCGI: has released connection
> for (
> Please let me know if there is any way to enable reuse of connection to
> the php-fpm process.
>                 Thanks,
>                                 Dean..

Born in Roswell... married an alien...

Born in Roswell... married an alien...

View raw message