The following example demonstrates how to use
stream_set_write_buffer to create an unbuffered stream.
<?php
$fp = fopen($file, "w");
if ($fp) {
if (stream_set_write_buffer($fp, 0) !== 0) {
// changing the buffering failed
}
fwrite($fp, $output);
fclose($fp);
}
?>