The nginx docs say that keepalive for fastcgi cannot work if the fastcgi_keep_conn is not on. However, I can't find any further details on this. I already have keepalive enabled server-wide. I am using php-fpm. Are there any issues about using fastcgi_keep_conn that I should be aware of?
fastcgi_keep_conn does increase performance, since the socket between nginx and PHP-FPM stays open after request has been processed. Therefore the time spent opening the socket is saved.
Overall, this would save some milliseconds on each request, so it has not such a big effect.
The documentation simply means that you need to have both an
upstream block with
keepalive option and
fastcgi_keep_conn option in your PHP script block for the connection keepalive to work.
fastcgi_keep_conn option tells nginx to make PHP-FPM to keep the connection open after the request, and the
keepalive connection tells nginx to keep the connection open.
You also need to set the
keepalive_requests option of your upstream to the same number as your php-fpm's
pm.max_requests, otherwise you might run into this problem:
Basically you can get one of the following errors every time a php-fpm child process restarts due to
pm.max_requests being reached while nginx is still connected to it:
readv() failed (104: Connection reset by peer) while reading upstream and recv() failed (104: Connection reset by peer) while reading response header from upstream