|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #23222 Allow controlling header flushing with output buffering
Submitted: 2003-04-15 03:13 UTC Modified: 2013-08-01 12:26 UTC
From: nospam at 1111-internet dot com Assigned: mike (profile)
Status: Wont fix Package: Zlib related
PHP Version: * OS: *
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: nospam at 1111-internet dot com
New email:
PHP Version: OS:


 [2003-04-15 03:13 UTC] nospam at 1111-internet dot com
Consider the following code:

echo str_repeat("x", 4095);
header("Location: /somewhere_else.php");

If zlib.output_compression is off, this will cause 4095 "x"s to display, properly followed by an error on the header line.

If zlib.output_compression is on, however, the echo line will execute - but nothing is output immediately because it fails to fill the compression buffer - so the header line goes ahead and executes and redirects successfully, completely spurning the output.

Granted, nobody would use this particular example in a real world application - I just set it up to illustrate the problem. I have run into real situations, though, where I'm doing diagnostics or inadvertently cause an error on code lines that logically precede a header("Location:... call. This problem prevents my diagnistic or error messages from showing up. Consider:

// set up mysql connection and
mysql_query("insert into mytable (myfield) values (". $_GET["myvalue"]. ")");

// no problem if $_GET["myvalue"] is a number,
// but if it's a non-numeric string like "abc" that line will generate an error message
// which I would like to see so I can fix the problem...

// but the error message doesn't fill the compression buffer
// so the following redirect happens and usurps the error message
header("Location: /somewhere_else.php");

// so I go on as though there was never a problem
// until I look at my still-empty database table some time later...


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-04-15 06:05 UTC]
This is not a bug, but a feature of PHP's output buffering. Whenever you have any sort of output buffering enabled header() function will work until the buffers are flushed to the output.
 [2003-04-15 09:28 UTC] nospam at 1111-internet dot com
I could see how that could be considered a "feature" to some, but for the reasons I've already stated I see it only as an unwanted and undesirable side effect.

I request that another feature be added that allows one to override this default behavior, i.e.:

zlib.output_compression = On
zlib.header_flush = On

which would cause the output buffer to flush immediately before each header() is executed.

 [2003-04-15 20:10 UTC]
As previously indicated by this is not a bug, but rather a feature resultant from automatic output buffering when compression is enabled. Therefor the bug status is being changed accordingly.
 [2011-01-01 20:39 UTC]
-Summary: anomaly re: zlib.output_compression and header("Location:... +Summary: Allow controlling header flushing with output buffering -Package: Feature/Change Request +Package: Zlib related -Operating System: FreeBSD 4.8 +Operating System: * -PHP Version: 4.3.1 +PHP Version: *
 [2013-08-01 12:26 UTC]
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: mike
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Dec 05 06:01:23 2020 UTC