|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42473 ob_start php://output and headers
Submitted: 2007-08-29 17:15 UTC Modified: 2008-11-26 01:21 UTC
Avg. Score:3.2 ± 1.5
Reproduced:3 of 4 (75.0%)
Same Version:1 (33.3%)
Same OS:2 (66.7%)
From: ce at netage dot bg Assigned:
Status: Closed Package: Apache2 related
PHP Version: 5.2.6 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: ce at netage dot bg
New email:
PHP Version: OS:


 [2007-08-29 17:15 UTC] ce at netage dot bg
it is actually a duplicate problem with 40429, but since you have closed the bug I cannot reopen it, but it is still present with all versions including the new 5.2.4RC3
when open through a browser, not a cli!

Reproduce code:


$fp = fopen('php://output', 'w');
fwrite($fp, 'aaaaaaa');

$content = ob_get_clean();

header('Content-type: text/html');

echo $content;

Expected result:

Actual result:
Warning: Cannot modify header information - headers already sent in /var/www/test.php on line 13


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-30 09:54 UTC] ce at netage dot bg
from the documentation:

php://output allows you to write to the output buffer mechanism in the same way as print() and echo().

(taken from

so from the written the following code



echo 'aaaaaaa';

$content = ob_get_clean();

header('Content-type: text/html');

echo $content;


should be equivalent to the problematic code, but it it not! this code with echo does not yeld the warning

either fix the documentation, either the bug
 [2007-08-30 11:32 UTC]
I don't know what your php.ini settings are but I can't even reproduce it..

 [2007-08-30 13:39 UTC] ce at netage dot bg
I just compile the latest version 5.2.4RC3

./configure --with-apxs2=/usr/bin/apxs2 --prefix=/usr/local/php-5.2.4

no php.ini, so everything is default

but I have discovered that if using CGI server api it is not reproducable

this is from phpinfo()

I can give some other info for my configuration if needed

Build Date 	Aug 30 2007 15:09:33 
Configure Command 	'./configure' '--with-apxs2=/usr/bin/apxs2' '--prefix=/usr/local/php-5.2.4' 
Server API 	Apache 2.0 Handler 
Virtual Directory Support 	disabled 
Configuration File (php.ini) Path 	/usr/local/php-5.2.4/lib 
Loaded Configuration File 	(none) 
PHP API 	20041225 
PHP Extension 	20060613 
Zend Extension 	220060519 
Debug Build 	no
 [2007-08-30 13:54 UTC] ce at netage dot bg
with windows and apache and again Server API -> Apache 2.0 Handler
it is reproducable, so I suppose the problem is something connected to the server api

here the CGI version in action - no problem

ce@ce:/usr/local/php-5.2.4/bin$ ./php-cgi


$fp = fopen('php://output', 'w');
fwrite($fp, 'aaaaaaa');

$content = ob_get_clean();

header('X-z: 1');

echo $content;

X-Powered-By: PHP/5.2.4RC3
X-z: 1
Content-type: text/html

 [2007-09-10 12:58 UTC]
The bug is still present under Windows XP, PHP 5.2.4.

I'm using php.ini-recommended with display_errors = On.
 [2007-09-23 09:32 UTC] tzachi at zend dot com
The problem seems to be with fclose($fp) when $fp=php://output. fclose flushes headers and output in Apache handler(and filter, also it seems that in other SAPIs this situation will not occur), so headers are sent at this point. You can use this in order to partially fix:


$fp = fopen('php://output', 'w');
fwrite($fp, 'aaaaaaa');

$content = ob_get_clean();

header('Content-type: text/html');

echo $content;
 [2008-06-05 17:25 UTC] biggi at stefna dot is
I am getting this error as well. Using php-5.2.6 and Apache 2.0 handler.

I do not think the php://output stream should be affected by fclose since the stream really is not affected by fopen.

For information (example of a workaround):
 [2008-11-26 01:21 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Sep 26 23:01:24 2023 UTC