Skip to content

Instantly share code, notes, and snippets.

@juzna
Created January 16, 2012 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juzna/1620837 to your computer and use it in GitHub Desktop.
Save juzna/1620837 to your computer and use it in GitHub Desktop.
PHP Output Buffer bug
<?php
$path = "/tmp/ob.log";
$logHandle = fopen($path, 'w') or die("unable to open temp file");
ob_start(function($buffer) use ($logHandle) { fwrite($logHandle, $buffer); }, 20);
echo str_repeat("0", 20); // fill in the buffer
for($i = 0; $i < 10; $i++) {
echo str_pad($i, 9, ' ', STR_PAD_LEFT) . "\n"; // full buffer dumped every time
}
ob_end_flush();
fclose($logHandle);
printf("Output file size: %d, expected %d\n", filesize($path), 20 + 10 * 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment