|  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: 2021-12-01 22:36 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: bukka (profile)
Status: Duplicate Package: FPM related
PHP Version: 7.1.13 OS: Alpine
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: 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.
 [2021-11-30 22:09 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: bukka
 [2021-11-30 22:09 UTC]
Sorry for the delay in checking this out but I don't think there's anything wrong with this. At least I don't understand why you expect body to show if you set content-length to 0? I don't think FPM should modify it as it was explicitly set by the user so it will send it to the web server (nginx in your case) and body is then ignored.
 [2021-12-01 20:50 UTC]
-Status: Assigned +Status: Not a bug
 [2021-12-01 20:50 UTC]
I'm marking this as not a bug for now. If you still think that this is a bug, please update your ticket with a reasoning behind it.
 [2021-12-01 22:36 UTC]
-Status: Not a bug +Status: Duplicate
 [2021-12-01 22:36 UTC]
Sorry I know what this is about actually - it is most likely duplicate of
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Mar 27 11:03:36 2023 UTC