|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-08-10 18:08 UTC] dennis at nocertainty dot com
Description:
------------
When using ob_start('ob_gzhandler') and ob_clean() the output buffer is destroyed, and no ob_* function works anymore. It seems that PHP4 had this problem as well (http://bugs.php.net/bug.php?id=29125)
Reproduce code:
---------------
<?php
ob_start('ob_gzhandler');
echo 'Should NOT be shown';
ob_clean();
echo 'Should be shown';
?>
Expected result:
----------------
"Should be shown" should've been printed, instead nothing is returned, and nothing displays anymore.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 10:00:01 2025 UTC |
Still can't reproduce, even with FCGI. Does this work for you: <?php function foo($data) { return $data; } ob_start('foo'); echo 'Should NOT be shown'; ob_clean(); echo 'Should be shown'; ?> ?I've reproduced the bug. I've been wondering why my script wouldn't run until I saw this bug. I'm using apache server on win xp with php 4 as a module. The above code produced the bug: <?php ob_start('ob_gzhandler'); echo 'Should NOT be shown'; ob_clean(); echo 'Should be shown'; ?> With further debuging this doesn't work either: <?php function handler($buffer,$mode){ $buffer=ob_gzhandler($buffer,$mode); return $buffer; } ob_start('handler'); echo 'Should NOT be shown'; ob_clean(); echo 'Should be shown'; ?> I noticed that the content-length in my headers was non-zero so I tried this and lo and behold: <?php function handler($buffer,$mode){ $buffer=ob_gzhandler($buffer,$mode); header('Content-Encoding:'); header('Content-Type: text/plain'); header('Vary:'); return bin2hex($buffer); } ob_start('handler'); echo 'Should NOT be shown'; ob_clean(); echo 'Should be shown'; ?> I realized the bug is sending bad gz binary but for some reason the following code did work...: <?php function handler($buffer,$mode){ $buffer=ob_gzhandler($buffer,$mode); header('Content-Encoding:'); header('Content-Type: text/plain'); header('Vary:'); return gzuncompress($buffer); } ob_start('handler'); echo 'Should NOT be shown'; ob_clean(); echo 'Should be shown'; ?> To my surprise, this didn't, thus confusing me: <?php function handler($buffer,$mode){ $buffer=ob_gzhandler($buffer,$mode); header('Content-Encoding:'); header('Content-Type: text/plain'); header('Vary:'); return 'test'.gzuncompress($buffer); } ob_start('handler'); echo 'Should NOT be shown'; ob_clean(); echo 'Should be shown'; ?> I'll be looking for the source on cvs and report back to ya!this appears to be ob_gzhandler's fault. it seems to send the content-encoding: gzip header even if ob_end_clean or similar is called which produces no output. that means that if you use ob_gzhandler and then change your mind about compression and need to kill that buffer, you're out of luck. in the following small example, "output" WILL be printed in plaintext but will be misinterpreted by the browser as gzipped content. <?php ob_start("ob_gzhandler"); echo("trashed"); ob_end_clean(); echo("output"); ?> you can use telnet to better view the situation because it will almost always result in a white browser window. as others have pointed out, you have to use the accept-encoding to trigger ob_gzhandler's compression: $ telnet localhost 80 GET /ob_test.php HTTP/1.1 Host: localhost Accept-Encoding: gzip,deflate now, should ob_gzhandler really be sending the header if the buffer is ended without outputting anything? should it maybe check the length of the buffer when it is closed to determine whether or not the content-encoding header should be sent?You can't change your mind about compression in half way however you can still kill that buffer and send other. <?php ob_start("ob_gzhandler"); echo("trashed"); ob_end_clean(); ob_start("ob_gzhandler"); echo("output"); ob_end_flush(); ?>