Welcome! Log In Create A New Profile

Advanced

sendfile_max_chunk breaking unbufferred php-fcgi

June 14, 2015 09:52AM
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?
Subject Author Posted

sendfile_max_chunk breaking unbufferred php-fcgi

Floris June 14, 2015 09:52AM

Re: sendfile_max_chunk breaking unbufferred php-fcgi

Valentin V. Bartenev June 15, 2015 06:40AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 199
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready