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: 2018-01-25 08:15 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:
Status: Open Package: FPM related
PHP Version: 7.1.13 OS: Alpine
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Nov 17 01:01:35 2019 UTC