ID: 30264 User updated by: mpn at illearth dot net Reported By: mpn at illearth dot net -Status: Bogus +Status: Open Bug Type: Output Control Operating System: Win NT(2K) PHP Version: 4.3.9 New Comment:
I quote from the manual: http://us4.php.net/manual/en/function.ob-start.php "While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer." In particular "(other than headers)". So according to the documentation, headers are sent prior to buffer flushing, which is also consistent with the documentation for headers: http://us4.php.net/manual/en/function.header.php "Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP." Please explain what use this function has when you can't use it until all the content has been sent to the browser, at which point (barring a shutdown function) the script normally exits? Please try this test code: ----CUT---- blank<?php error_reporting( E_ALL ); header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); header( 'Cache-Control: no-store, no-cache, must-revalidate' ); header( 'Cache-Control: post-check=0, pre-check=0', FALSE ); header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' ); header( 'Pragma: no-cache' ); echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\n\n"; echo '<html><head>' . "\n";echo '<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />' . "\n";echo '<meta http-equiv="content-language" content="en-GB" />' . "\n"; echo '</head><body>headers_sent() Returned Value Is: ' . "\n"; var_dump( headers_sent() ); echo '</body></html>' . "\n"; flush(); header( 'Cache-Control: no-store, no-cache, must-revalidate' ); var_dump( headers_sent() ); ?> ----END CUT---- The behavior of this code is consitent with what you have stated, headers aren't sent prior to the flush, however when trying to send headers after flushing, you trigger a warning: Warning: Cannot modify header information - headers already sent in W:\MPN\CVS\rc2-2\mpn188\html\_test_headers.php on line 12 So I fail to see where this function can be used?? The only good reason I can see for testing if headers have been sent is to determine if you can successfully send more headers. As the above code shows, you cannot send anymore headers once flushing, which is the only location in the script that you get a TRUE return from headers_sent(). At the very least this qualifies as documentation problems or possibly add to the list of soon to be deprecated functions. Previous Comments: ------------------------------------------------------------------------ [2004-09-29 15:35:37] [EMAIL PROTECTED] 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 What makes you think headers should have been sent at the point where you call headers_sent()? I would not expect this to happen until the ob_end_flush() call. ------------------------------------------------------------------------ [2004-09-28 18:33:41] mpn at illearth dot net Description: ------------ When checking the value of headers_sent(), function is returning FALSE even though headers have clearly been sent. Returned result does not change when output buffering is commented out or where output buffering is started (i.e before sending headers or after ). I crammed the test code into 19 lines, so please excuse the formatting. ["SERVER_SOFTWARE"]=> string(31) "Apache/2.0.49 (Win32) PHP/4.3.9" using sapi Reproduce code: --------------- <?php ob_clean(); if ( stristr( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) ) { ob_start( 'compressOutput' ); } else { ob_start(); } header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); header( 'Cache-Control: no-store, no-cache, must-revalidate' ); header( 'Cache-Control: post-check=0, pre-check=0', FALSE ); header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' ); header( 'Pragma: no-cache' ); echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\n\n"; echo '<html><head>' . "\n";echo '<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />' . "\n";echo '<meta http-equiv="content-language" content="en-GB" />' . "\n"; echo '</head><body>headers_sent() Returned Value Is: ' . "\n"; var_dump( headers_sent() ); echo '</body></html>' . "\n"; ob_end_flush(); function compressOutput( $str ) { $_output = gzencode( $str ); if ( (bool)FALSE === $_output ) { return $str; } header( 'Content-Encoding: gzip' ); return $_output; } // End Function compressOutput ?> Expected result: ---------------- var_dump( headers_sent() ); = (bool)true Actual result: -------------- var_dump( headers_sent() ); = (bool)false ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=30264&edit=1