|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75870 header() terminates execution when Content-Length is 0
Submitted: 2018-01-24 18:03 UTC Modified: 2018-01-25 08:15 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: km dot wrona at gmail dot com Assigned:
Status: Open Package: FPM related
PHP Version: 7.1.13 OS: Alpine
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: km dot wrona at gmail dot com
New email:
PHP Version: OS:


 [2018-01-24 18:03 UTC] km dot wrona at gmail dot com
header() terminates execution when content-length is 0

This happens on Alpine3.7 php 7.1.12, for some reason not available in the list above. 

It works fine on Ubuntu 16.04 php 7.1.13

Test script:
header('content-length: 0', false, null);
echo 'this is longer than 0';

Expected result:
this is longer than 0

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-01-24 20:23 UTC]
-Status: Open +Status: Feedback
 [2018-01-24 20:23 UTC]
What web server (Apache, nginx, etc.) and how is PHP running (like via module or FPM)?

And are you sure *execution* stops or can you simply not see the output? Try something like touch()ing a file.
 [2018-01-24 21:30 UTC] km dot wrona at gmail dot com
-Status: Feedback +Status: Open
 [2018-01-24 21:30 UTC] km dot wrona at gmail dot com
nginx 1.12.2
php-fpm 7.1.12

I've changed the test script in accordance with your advice to the following:
header('content-length: 0', false, null);

Neither the file was created nor the "done" was displayed.

I've rebuilt my container to use php7.2.1 and it's exactly the same.
 [2018-01-24 22:49 UTC] spam2 at rhsoft dot net
cause and effect

pretty sure beause of the empty content-length the connection to the fcgi-worker is closed and so as result the script terminated - either use output-buffering or user_abort_ignore(true) and that would be impossible to happen beause with output buffering anything starts to hits the cient *after* the whole script has finished and most applications use ob_stzart() anyways to have the capability send headers at any point in time
 [2018-01-24 23:12 UTC]
-Status: Open +Status: Feedback -Package: *General Issues +Package: FPM related
 [2018-01-24 23:12 UTC]
Were permissions on /var/www/html set to allow the new file? Try in /tmp instead.
And do you have the gzip module installed and enabled in nginx? Try without.
 [2018-01-25 00:49 UTC] km dot wrona at gmail dot com
-Status: Feedback +Status: Open
 [2018-01-25 00:49 UTC] km dot wrona at gmail dot com
Modified the script again to be:
header('content-length:0',false, null);

Both 1 and 2 exist, no "done" is displayed, so it looks like it does not terminate...
 [2018-01-25 00:52 UTC]
-Status: Open +Status: Feedback
 [2018-01-25 00:52 UTC]
Can you check that gzip thing with nginx? Though I haven't seen anything to explicitly state it cuts off content, I know it will respect a Content-Length to some degree.
 [2018-01-25 08:15 UTC] km dot wrona at gmail dot com
-Status: Feedback +Status: Open
 [2018-01-25 08:15 UTC] km dot wrona at gmail dot com
No gzip enabled.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Jul 30 15:01:23 2021 UTC