Eu configurei mod_proxy_fcgi
para ir com o apache e php-fpm
. Se eu ler a especificação FCGI corretamente, o fluxo típico para a comunicação entre um servidor é manter as conexões entre o servidor da Web e o servidor FastCGI abertas enquanto elas estiverem ativas. No entanto, observo comportamento diferente. O Apache parece fechar a conexão após cada solicitação.
Aqui estão as partes relevantes de httpd.conf
:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
...
ProxyPass / fcgi://127.0.0.1:9000/usr/local/apache2/htdocs/ ttl=120
ProxyErrorOverride on
Eu defino LogLevel
para debug
. Eu recebo os seguintes logs quando executo algumas solicitações em um loop (há muito pouco tempo entre as solicitações, então eu realmente não esperaria nenhum tempo limite):
[Mon Oct 07 12:43:49.338770 2013] [authz_core:debug] [pid 29880:tid 140162482755328] mod_authz_core.c(828): [client 127.0.0.1:36279] AH01628: authorization result: granted (no directives)
[Mon Oct 07 12:43:49.338793 2013] [proxy_fcgi:debug] [pid 29880:tid 140162482755328] mod_proxy_fcgi.c(120): [client 127.0.0.1:36279] AH01060: set r->filename to proxy:fcgi://127.0.0.1:9000/usr/local/apache2/htdocs/info.php
[Mon Oct 07 12:43:49.338802 2013] [proxy:debug] [pid 29880:tid 140162482755328] mod_proxy.c(1083): [client 127.0.0.1:36279] AH01143: Running scheme fcgi handler (attempt 0)
[Mon Oct 07 12:43:49.338807 2013] [proxy_http:debug] [pid 29880:tid 140162482755328] mod_proxy_http.c(2174): [client 127.0.0.1:36279] AH01113: HTTP: declining URL fcgi://127.0.0.1:9000/usr/local/apache2/htdocs/info.php
[Mon Oct 07 12:43:49.338812 2013] [proxy_fcgi:debug] [pid 29880:tid 140162482755328] mod_proxy_fcgi.c(944): [client 127.0.0.1:36279] AH01076: url: fcgi://127.0.0.1:9000/usr/local/apache2/htdocs/info.php proxyname: (null) proxyport: 0
[Mon Oct 07 12:43:49.338816 2013] [proxy_fcgi:debug] [pid 29880:tid 140162482755328] mod_proxy_fcgi.c(954): [client 127.0.0.1:36279] AH01078: serving URL //127.0.0.1:9000/usr/local/apache2/htdocs/info.php
[Mon Oct 07 12:43:49.338821 2013] [proxy:debug] [pid 29880:tid 140162482755328] proxy_util.c(2013): AH00942: FCGI: has acquired connection for (127.0.0.1)
[Mon Oct 07 12:43:49.338826 2013] [proxy:debug] [pid 29880:tid 140162482755328] proxy_util.c(2065): [client 127.0.0.1:36279] AH00944: connecting //127.0.0.1:9000/usr/local/apache2/htdocs/info.php to 127.0.0.1:9000
[Mon Oct 07 12:43:49.338887 2013] [proxy:debug] [pid 29880:tid 140162482755328] proxy_util.c(2187): [client 127.0.0.1:36279] AH00947: connected /usr/local/apache2/htdocs/info.php to 127.0.0.1:9000
[Mon Oct 07 12:43:49.339232 2013] [proxy:debug] [pid 29880:tid 140162482755328] proxy_util.c(2028): AH00943: FCGI: has released connection for (127.0.0.1)
[Mon Oct 07 12:43:49.343980 2013] [authz_core:debug] [pid 28752:tid 140162457577216] mod_authz_core.c(828): [client 127.0.0.1:36282] AH01628: authorization result: granted (no directives)
[Mon Oct 07 12:43:49.344001 2013] [proxy_fcgi:debug] [pid 28752:tid 140162457577216] mod_proxy_fcgi.c(120): [client 127.0.0.1:36282] AH01060: set r->filename to proxy:fcgi://127.0.0.1:9000/usr/local/apache2/htdocs/info.php
[Mon Oct 07 12:43:49.344018 2013] [proxy:debug] [pid 28752:tid 140162457577216] mod_proxy.c(1083): [client 127.0.0.1:36282] AH01143: Running scheme fcgi handler (attempt 0)
[Mon Oct 07 12:43:49.344024 2013] [proxy_http:debug] [pid 28752:tid 140162457577216] mod_proxy_http.c(2174): [client 127.0.0.1:36282] AH01113: HTTP: declining URL fcgi://127.0.0.1:9000/usr/local/apache2/htdocs/info.php
[Mon Oct 07 12:43:49.344028 2013] [proxy_fcgi:debug] [pid 28752:tid 140162457577216] mod_proxy_fcgi.c(944): [client 127.0.0.1:36282] AH01076: url: fcgi://127.0.0.1:9000/usr/local/apache2/htdocs/info.php proxyname: (null) proxyport: 0
[Mon Oct 07 12:43:49.344033 2013] [proxy_fcgi:debug] [pid 28752:tid 140162457577216] mod_proxy_fcgi.c(954): [client 127.0.0.1:36282] AH01078: serving URL //127.0.0.1:9000/usr/local/apache2/htdocs/info.php
[Mon Oct 07 12:43:49.344038 2013] [proxy:debug] [pid 28752:tid 140162457577216] proxy_util.c(2013): AH00942: FCGI: has acquired connection for (127.0.0.1)
[Mon Oct 07 12:43:49.344043 2013] [proxy:debug] [pid 28752:tid 140162457577216] proxy_util.c(2065): [client 127.0.0.1:36282] AH00944: connecting //127.0.0.1:9000/usr/local/apache2/htdocs/info.php to 127.0.0.1:9000
[Mon Oct 07 12:43:49.344082 2013] [proxy:debug] [pid 28752:tid 140162457577216] proxy_util.c(2187): [client 127.0.0.1:36282] AH00947: connected /usr/local/apache2/htdocs/info.php to 127.0.0.1:9000
[Mon Oct 07 12:43:49.344397 2013] [proxy:debug] [pid 28752:tid 140162457577216] proxy_util.c(2028): AH00943: FCGI: has released connection for (127.0.0.1)
Eu vejo essa linha FCGI: has released connection for (127.0.0.1)
repetindo uma e outra vez. Eu olhei dentro da implementação do Apache2. Aqui estão os bits relevantes:
PROXY_DECLARE(int) ap_proxy_release_connection(const char *proxy_function,
proxy_conn_rec *conn,
server_rec *s)
{
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00943)
"%s: has released connection for (%s)",
proxy_function, conn->worker->s->hostname);
connection_cleanup(conn);
return OK;
}
...
PROXY_DECLARE(int) ap_proxy_connection_reusable(proxy_conn_rec *conn)
{
proxy_worker *worker = conn->worker;
return ! (conn->close || !worker->s->is_address_reusable || worker->s->disablereuse);
}
...
static apr_status_t connection_cleanup(void *theconn)
{
...
/* determine if the connection need to be closed */
if (!ap_proxy_connection_reusable(conn)) {
apr_pool_t *p = conn->pool;
apr_pool_clear(p);
conn = apr_pcalloc(p, sizeof(proxy_conn_rec));
conn->pool = p;
conn->worker = worker;
apr_pool_create(&(conn->scpool), p);
apr_pool_tag(conn->scpool, "proxy_conn_scpool");
}
...
}
Eu coloquei alguns logs adicionais e recompilei o Apache e obtive que conn->close
seja true e worker->s->is_address_reusable
seja false. Alguma pista sobre o que está mal configurado?
Muito obrigado!