stream_set_write_buffer()

stream_set_write_buffer() — Sets write file buffering on the given stream.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

Sets the buffering for write operations on the given stream to size bytes.

Signature

stream_set_write_buffer(resource $stream, int $size): int

Parameters

ParameterTypeWhat it takes
$streamresourceThe file pointer.
$sizeintThe number of bytes to buffer. If size is 0 then write operations are unbuffered. This ensures that all writes with fwrite() are completed before other processes are allowed to write to that output stream.

Return value

Returns 0 on success, or another value if the request cannot be honored.

Example

A runnable snippet:

$fp = fopen($file, "w"); if ($fp) { if (stream_set_write_buffer($fp, 0) !== 0) { // changing the buffering failed } fwrite($fp, $output); fclose($fp); }

See also

fopen(), fwrite()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page stream_set_write_buffer() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.