sendfile_max_chunk breaking unbufferred php-fcgi
Floris
nginx-forum at nginx.us
Sun Jun 14 13:52:26 UTC 2015
Hi,
I was having the problem that if a single client on the local LAN is
downloading a large static file, the download is effectively monopolizing
nginx, and no other requests are handled simultaneously.
Reading the manual I came across the sendfile_max_chunk option that sounded
like that may fix it:
==
Syntax: sendfile_max_chunk size;
Default: sendfile_max_chunk 0;
Context: http, server, location
When set to a non-zero value, limits the amount of data that can be
transferred in a single sendfile() call. Without the limit, one fast
connection may seize the worker process entirely.
==
However I noticed that if I enable that, PHP scripts running without
buffering suddenly no longer work properly.
nginx.conf:
==
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 80;
server_name $hostname;
sendfile on;
sendfile_max_chunk 8192;
root /var/www;
location / {
index index.php index.html index.htm;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_buffering off;
fastcgi_pass unix:/var/run/php-fpm.sock;
include fastcgi.conf;
}
}
}
==
t2.php for testing purposes:
==
<?php
for ($i = 0; $i < 10; $i++)
{
echo "test!\n";
flush();
sleep(1);
}
==
When retrieving that, the connection stalls after the first flush:
==
$ telnet 192.168.178.26 80
Trying 192.168.178.26...
Connected to 192.168.178.26.
Escape character is '^]'.
GET /t2.php HTTP/1.0
HTTP/1.1 200 OK
Server: nginx/1.6.3
Date: Sun, 14 Jun 2015 13:21:53 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
X-Powered-By: PHP/5.6.9
test!
==
If I remove either the "sendfile_max_chunk 8192;" or "fastcgi_buffering
off;" line it does work, and I do get all 10 test! messages:
==
telnet 192.168.178.26 80
Trying 192.168.178.26...
Connected to 192.168.178.26.
Escape character is '^]'.
GET /t2.php HTTP/1.0
HTTP/1.1 200 OK
Server: nginx/1.6.3
Date: Sun, 14 Jun 2015 13:22:23 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
X-Powered-By: PHP/5.6.9
test!
test!
test!
test!
test!
test!
test!
test!
test!
test!
Connection closed by foreign host.
==
Am I doing something wrong, or is this a bug?
Posted at Nginx Forum: http://forum.nginx.org/read.php?2,259603,259603#msg-259603
More information about the nginx
mailing list