Example 1 — Disable Write Buffering
Open a temp file, turn off the write buffer, and print the result code.
<?php
$path = sys_get_temp_dir() . '/codetofun_write_buf.txt';
$stream = fopen($path, 'w');
$result = stream_set_write_buffer($stream, 0);
echo 'result=', $result, PHP_EOL;
fwrite($stream, "line one\n");
fclose($stream);
unlink($path); How It Works
- fopen() opens a real file stream for writing.
- stream_set_write_buffer($stream, 0) requests unbuffered writes.
- A return of 0 means success.
- fwrite() then goes out without waiting for a full buffer.

