Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP-FPM - upstream prematurely closed connection while reading response header

Tags:

php

nginx

apc

Already saw this same question - upstream prematurely closed connection while reading response header from upstream, client But as Jhilke Dai said it not solved at all and i agree. Got same exact error on nginx+phpFPM installation. Current software versions: nginx 1.2.8 php 5.4.13 (cli) on FreeBSd9.1. Actually bit isolated this error and sure it happened when trying to import large files, larger than 3 mbs to mysql via phpMyadmin. Also counted that backend closing connection when 30 secs limit reached. Nginx error log throwing this

 [error] 49927#0: *196 upstream prematurely closed connection while reading response header from upstream, client: 7X.XX.X.6X, server: domain.com, request: "POST /php3/import.php HTTP/1.1", upstream: "fastcgi://unix:/tmp/php5-fpm.sock2:", host: "domain.com", referrer: "http://domain.com/phpmyadmin/db_import.php?db=testdb&server=1&token=9ee45779dd53c45b7300545dd3113fed"

My php.ini limits raised accordingly

upload_max_filesize = 200M
default_socket_timeout = 60
max_execution_time = 600
max_input_time = 600

my.cnf related limit

max_allowed_packet = 512M

Fastcgi limits

location ~ \.php$ {
# fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass unix:/tmp/php5-fpm.sock2;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;

fastcgi_intercept_errors on;
fastcgi_ignore_client_abort on;
fastcgi_connect_timeout 60s;
fastcgi_send_timeout 200s;
fastcgi_read_timeout 200s;
fastcgi_buffer_size 128k;
fastcgi_buffers 8 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;

Tried to change fastcgi timeouts as well buffer sizes, that's not helped. php error log doesn't show problem, enabled all notices, warning - nothing useful. Also tried disable APC - no effect.

like image 364
Demontager Avatar asked May 04 '13 20:05

Demontager


1 Answers

I had this same issue, got 502 Bad Gateway frequently and randomly at my development machine (OSX + nginx + php-fpm), and solved it by changing some parameters at /usr/local/etc/php/5.6/php-fpm.conf:

I had this settings:

 pm = dynamic
 pm.max_children = 10
 pm.start_servers = 3
 pm.max_spare_servers = 5

... and changed them to:

pm = dynamic
pm.max_children = 10
pm.start_servers = 10
pm.max_spare_servers = 10

... and then restarted the php-fpm service.

This settings are based on what I found here: [https://bugs.php.net/bug.php?id=63395]

like image 192
Mirko Avatar answered Sep 19 '22 01:09

Mirko