|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67583 double fastcgi_end_request on max_children limit
Submitted: 2014-07-07 10:37 UTC Modified: 2018-02-15 16:16 UTC
Avg. Score:4.2 ± 0.9
Reproduced:5 of 5 (100.0%)
Same Version:1 (20.0%)
Same OS:1 (20.0%)
From: saprykin dot dmitry at gmail dot com Assigned: nikic (profile)
Status: Closed Package: FPM related
PHP Version: 5.5.14 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: saprykin dot dmitry at gmail dot com
New email:
PHP Version: OS:


 [2014-07-07 10:37 UTC] saprykin dot dmitry at gmail dot com
Php sends 2 fastcgi FCGI_END_REQUEST records instead of one when fastcgi_finish_request(); called and fpm param max_requests exceeded.

* one is sent on fastcgi_finish_request(); call
* other is sent in block  


if (max_requests && (requests == max_requests)) { 
    fcgi_finish_request(&request, 1); 

I have created pull request for this bug
It confuses fastcgi client (i.e. nginx) receiving 2 FCGI_END_REQUEST records one after another.

Test script:



Nginx configuration

upstream fpm
    keepalive 1;

    fastcgi_keep_conn on;
    fastcgi_param SCRIPT_NAME /index.php;
    fastcgi_pass fpm;

PHP FPM configuration

max_children = 1
max_requests = 2

Expected result:
No errors in nginx error log

Actual result:
Every second request is finished with 502 status

Nginx error.log contains records:

2014/07/07 13:42:58 [error] 11253#0: *1 upstream sent unexpected FastCGI record: 3 while reading response header from upstream, client:, server: localhost, request: "GET /nginx_test.phtml HTTP/1.1", upstream: "fastcgi://", host: "localhost:8081"


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-07 11:18 UTC] saprykin dot dmitry at gmail dot com
-PHP Version: Irrelevant +PHP Version: 5.5.14
 [2014-07-07 11:18 UTC] saprykin dot dmitry at gmail dot com
Changed PHP Version
 [2015-02-04 16:36 UTC] sdgf at example dot com
I see the pull request is merged. Is this fixed in any stable PHP release?
 [2015-02-05 05:17 UTC] saprykin dot dmitry at gmail dot com
No. It is not merged. It is just labeled as bugfix. See php-src/710 request
 [2015-03-10 09:42 UTC] reallfqq-php at yahoo dot fr
Pull request is invalid (made against a tag)
Pull request is broken (linked branch has been deleted)

Could someone have a look and add the needed line somewhere?

Small problem with a quick fix having an important impact.
 [2017-01-07 21:54 UTC]
Automatic comment on behalf of nikic
Log: Fixed bug #67583
 [2017-01-07 21:54 UTC]
-Status: Open +Status: Closed
 [2018-02-15 16:05 UTC] ablagoev at xs-software dot com
Hey all,

Will this fix be applied for php 5.6 too, as it seems present only in the php 7.xx line.
 [2018-02-15 16:16 UTC]
-Assigned To: +Assigned To: nikic
 [2018-02-15 16:16 UTC]
Nope, as PHP 5.6 is no longer actively support. Only security fixes may be applied to PHP 5.6.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Mar 04 18:01:42 2024 UTC