|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75776 Flushing streams with compression filter is broken
Submitted: 2018-01-08 03:27 UTC Modified: 2021-02-16 18:02 UTC
From: shestero at meta dot ua Assigned: cmb (profile)
Status: Closed Package: Streams related
PHP Version: 7.0.27 OS: Debian
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: shestero at meta dot ua
New email:
PHP Version: OS:


 [2018-01-08 03:27 UTC] shestero at meta dot ua
I used this way to produce compressed output for years but now it return zero-output without any errors anywhere.

Registered Stream Filters:	zlib.*, bzip2.*, convert.iconv.*, mcrypt.*, mdecrypt.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk

My configure parameters:
'./configure' '--with-openssl' '--with-ssl=/usr/bin/openssl' '--with-ssl-lib=/usr/lib/x86_64-linux-gnu' '--with-libdir=lib/x86_64-linux-gnu' '--with-bz2' '--enable-exif' '--with-gd' '--with-mcrypt' '--with-mysql' '--with-mysql-sock' '--enable-sockets' '--enable-zip' '--with-apxs2=/usr/bin/apxs2' '--with-config-file-path=/var/lib/apache2/conf' '--with-jpeg-dir' '--enable-gd-native-ttf' '--with-xmlrpc' '--with-freetype-dir' '--with-zlib' '--with-zlib-dir' '--enable-maintainer-zts' '--with-tsrm-pthreads' '--with-mysqli' '--enable-mbstring' '--with-pdo-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--with-curl' '--enable-memcache'

PS Output mute as I adding compression filters. string.toupper and string.tolower work!

Test script:
error_reporting(E_ALL); ini_set("display_errors", 1);
	if (true)
	  header("Content-Description: File Transfer");
	  header("Content-Disposition: attachment; filename=main.csv.bz2");
	  header("Content-Type: application/x-bzip2");
	  header("Content-Transfer-Encoding: binary");
	  header("Content-Type: application/csv");
	  header("Content-Disposition: attachment;Filename=main.csv");

	$bz = fopen('php://output', 'w');

fwrite($bz,"sdfgdfg"); // output such way

	stream_filter_append($bz, 'convert.iconv.UTF-8/CP1251//TRANSLIT'); // ok

	if (true)
	  $param = array('blocks' => 6, 'work' => 0); // for bzip2
	  $ok = stream_filter_append($bz, 'bzip2.compress', STREAM_FILTER_WRITE, $param);
	  // $param = array('level' => 6, 'window' => 15, 'memory' => 9); // for gzip
	  //$ok = stream_filter_append($bz, 'zlib.deflate');//, STREAM_FILTER_WRITE, $param);
	  if ($ok===false)
	    die("Cannot stream_filter_append( 'bzip2.compress' ) !");

Expected result:
error or some output as usual

Actual result:
browser saves zero-size file.


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-01-08 03:30 UTC] shestero at meta dot ua
fwrite($bz,"sdfgdfg"); // output such way

of cause at the end.
The existing code used about 5-6 years with different PHP versions so I'm quite sure it's ok.
 [2018-01-09 14:37 UTC]
-Status: Open +Status: Verified
 [2018-01-09 14:37 UTC]
Seems to be caused by the fflush() call.
 [2018-01-10 02:08 UTC] shestero at meta dot ua
Really commenting fflush solves the problem?

But what's wrong with fflush? I process data streaming and sometimes fill it should be flushed after some portion is over.
 [2018-01-10 02:09 UTC] shestero at meta dot ua
Commenting fflush solves the problem. I checked.
 [2021-02-15 14:08 UTC]
-Package: *Compression related +Package: Streams related
 [2021-02-15 14:08 UTC]
With regard to zlib.deflate this is a duplicate of bug #48725,
which is fixed as of PHP 7.4.14 and 8.0.1, respectively, but
apparently bzip2.compress has the same problem.

Recatogorizing as "streams related" since "filter related" is
used too often for ext/filter.
 [2021-02-16 18:02 UTC]
-Summary: compression filters on stdout not working any more +Summary: Flushing streams with compression filter is broken -Assigned To: +Assigned To: cmb
 [2021-02-16 18:02 UTC]
While having a closer look at the bzip2 issue, I noticed that the
fix for the other bug does not fully resolve the flushing issue
for zlib compression streams.

Anyhow, this is not particularly related to php://output streams,
but affects streams generally.  Furthermore, not only fflush()
triggers the misbehavior, but also other function calls, such as
rewind(), which flush the stream internally.
 [2021-02-16 18:45 UTC]
The following pull request has been associated:

Patch Name: Fix #75776: Flushing streams with compression filter is broken
On GitHub:
 [2021-02-22 14:35 UTC]
Automatic comment on behalf of
Log: Fix #75776: Flushing streams with compression filter is broken
 [2021-02-22 14:35 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 22 20:01:32 2024 UTC