|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-08-29 17:15 UTC] ce at netage dot bg
Description:
------------
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:
---------------
<?php
ob_start();
$fp = fopen('php://output', 'w');
fwrite($fp, 'aaaaaaa');
fclose($fp);
$content = ob_get_clean();
header('Content-type: text/html');
echo $content;
Expected result:
----------------
aaaaaaa
Actual result:
--------------
Warning: Cannot modify header information - headers already sent in /var/www/test.php on line 13
aaaaaaa
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 03:00:02 2025 UTC |
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 <?php error_reporting(E_ALL); ob_start(); $fp = fopen('php://output', 'w'); fwrite($fp, 'aaaaaaa'); fclose($fp); $content = ob_get_clean(); header('X-z: 1'); echo $content; X-Powered-By: PHP/5.2.4RC3 X-z: 1 Content-type: text/html aaaaaaace@ce:/usr/local/php-5.2.4/bin$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: <?php ob_start(); $fp = fopen('php://output', 'w'); fwrite($fp, 'aaaaaaa'); $content = ob_get_clean(); header('Content-type: text/html'); echo $content; fclose($fp);