php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25701 Calling flush from within an output buffer prevents headers from being sent
Submitted: 2003-09-30 09:56 UTC Modified: 2004-04-21 20:28 UTC
Votes:6
Avg. Score:4.8 ± 0.4
Reproduced:5 of 5 (100.0%)
Same Version:5 (100.0%)
Same OS:4 (80.0%)
From: scottmacvicar at ntlworld dot com Assigned: iliaa (profile)
Status: Closed Package: Apache2 related
PHP Version: 4CVS OS: *
Private report: No CVE-ID: None
 [2003-09-30 09:56 UTC] scottmacvicar at ntlworld dot com
Description:
------------
Calling flush in Apache and Apache 2 produce different results.

Within Apache after calling flush you can still send headers as the output buffer prevents it from actually being flushed.

Within Apache 2 after calling flush you can no longer send headers even though headers_sent still returns false.


Reproduce code:
---------------
<?php

ob_start();

echo 'test';
flush();

$newtext = ob_get_clean();

if (strpos(' ' . $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false AND !headers_sent())
{
	header('Content-Encoding: gzip');
	$newtext = gzencode($newtext, 1);
}

header('Content-Length: ' . strlen($newtext));
echo $newtext;

?>

Expected result:
----------------
test

Actual result:
--------------
binary data

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-30 18:47 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Unlike Apache 1, when Apache 2 recieves a directive to flush it does so right away sending any pending headers in the process. Since the headers & text were already sent it cannot send the header indicating the data that follows in gziped. Due to the missing header you get a whole bunch of binary data.
 [2003-09-30 19:22 UTC] scottmacvicar at ntlworld dot com
Shouldn't headers_sent() return true then?
 [2003-10-01 10:30 UTC] scottmacvicar at ntlworld dot com
<?php

ob_start();

echo 'test';
flush();

$newtext = ob_get_clean();

if (!headers_sent())
{
	echo 'in here<br />';
}

echo $newtext;

?>

Based on what you've said above then you shouldn't see 'in here' within Apache 2.
 [2003-10-01 23:22 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 20:01:29 2024 UTC