php.net |  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
Votes:1
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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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
Description:
------------
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:
---------------
<?php
header('content-length: 0', false, null);
echo 'this is longer than 0';
exit;

Expected result:
----------------
this is longer than 0

Actual result:
--------------
NOTHING (BLANK)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-01-24 20:23 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2018-01-24 20:23 UTC] requinix@php.net
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);
touch('/var/www/html/'.time());
die('done');
----

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

http://php.net/manual/de/function.ignore-user-abort.php
http://php.net/manual/de/function.ob-start.php
 [2018-01-24 23:12 UTC] requinix@php.net
-Status: Open +Status: Feedback -Package: *General Issues +Package: FPM related
 [2018-01-24 23:12 UTC] requinix@php.net
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:
----
touch('/tmp/1');
header('content-length:0',false, null);
touch('/tmp/2');
die('done');
----

Both 1 and 2 exist, no "done" is displayed, so it looks like it does not terminate...
 [2018-01-25 00:52 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2018-01-25 00:52 UTC] requinix@php.net
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] bukka@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: bukka
 [2021-11-30 22:09 UTC] bukka@php.net
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] bukka@php.net
-Status: Assigned +Status: Not a bug
 [2021-12-01 20:50 UTC] bukka@php.net
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] bukka@php.net
-Status: Not a bug +Status: Duplicate
 [2021-12-01 22:36 UTC] bukka@php.net
Sorry I know what this is about actually - it is most likely duplicate of https://bugs.php.net/bug.php?id=72185
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 18:01:34 2024 UTC