Upstream closed connection

Hi,

I’m using Nginx+PHP+MySQL on CentOS since two weeks and it works great
(with 20 000 visitors/day).

But every minutes, I received several errors like this one :

2008/09/16 12:39:30 [error] 25031#0: 5786740 upstream prematurely
closed connection while reading response header from upstream, client:
99.99.9.199, server: localhost, request: “GET /search?query=test&pag
e_number=8 HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”, host:
"www.
.com", referrer:
"http://www.
*.com/search?query=test&page_number=7"

My only clues are:

1- “fastcgi_read_timeout 180;” doesn’t solve my problem.

2- The error occured before executing the first line of my php script.
So, it’s not a MySQL problem, nor a php script problem.

3- There was a lot of “TIME_WAIT” connections on the fast_cgi program
(1000 time_wait for 1500 connections). I activated the
tcp_time_wait_recycler, the time_wait connections decreased but the
problem is still there.

4- I tested 5 php-cgi and 20 php-cgi : the error rating is the same.

5- More traffic increase the number of errors.

Do you have an advice? A way to debug this problem?
Any help?

Thanks a lot!


I use:
. Nginx 0.6.32
. PHP 5.1.6
. MySQL 5.0.45
. spawn-fcgi 1.4.19

My nginx.conf

user apache apache;
worker_processes 2;

events
{
worker_connections 1024;
}

http
{
include mime.types;
default_type application/octet-stream;

log_format main ‘$remote_addr [$time_local]
“$request” $status $body_bytes_sent “$http_referer”’;
access_log logs/access.log main;

sendfile on;
keepalive_timeout 65;

gzip on;
gzip_types text/plain text/html text/css
application/x-javascript text/xml application/xml application/xml+rss
text/javascript;

server
{
listen 80;
server_name localhost;

     root         /home/webmaster/www;


     location /
        {
           index  index.php;
           rewrite ^/?$                         /index.php

last;
rewrite ^/?index.php$ /index.php
last;
rewrite ^/?page_number=([0-9])$
/index.php?page_number=$1 last;
rewrite ^/?(.
)$ /search.php?query=$1
last;
}

     # PHP configuration
     location ~ .*\.php$
        {
           fastcgi_pass   127.0.0.1:9000;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME

/home/webmaster/www$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param REDIRECT_STATUS 200;
}

     # Static files configuration
     location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$
        {
           access_log        off;
           expires           30d;
        }
  }

}

I didn’t find the origin of my “upstream prematurely closed connection
while reading response header from upstream” error, but since I changed
spawn-fcgi to php-fpm, there is no more error.

So, today, the lesson is “use php-fpm” (http://php-fpm.anight.org/)

I could have told you that :slight_smile:

Mike, you are getting paid by Andrei, right :slight_smile:

The best exposure would be to get included finally into PHP core and
then it will be readily available, but until then, keep on doing the
advertising campaign :slight_smile:

Quite the opposite! I actually offered to pay him to help expedite
things :slight_smile:

It simply is the best way to manage php under fastcgi. I had an idea
that kind of resembled php-fpm, and while asking around for someone to
make it, I was pointed to php-fpm. I had never heard or known about
it. Not enough exposure.

As I don’t know C I’m doing my best to help the project… Which is
getting exposure and getting the name out there. :slight_smile:

On Sep 23, 2008, at 12:06 PM, “Kiril A.” [email protected]