Example 1 — Turn Off Write Buffering
Open a file for writing and tell PHP not to buffer the output.
<?php
$file = sys_get_temp_dir() . '/buffer_demo.txt';
$handle = fopen($file, 'w');
$result = set_file_buffer($handle, 0);
echo 'Result: ', $result, PHP_EOL;
fclose($handle);
unlink($file); How It Works
- fopen() opens a new file for writing and gives us a stream handle.
- set_file_buffer() with size 0 asks PHP to write data immediately.
- The function returns 0 when the request is accepted, so the script prints Result: 0.
- The file is closed and removed to keep the example clean.

