Current Location: Home> Function Categories> stream_set_write_buffer

stream_set_write_buffer

Set write file buffering on a given stream
Name:stream_set_write_buffer
Category:Stream
Programming Language:php
One-line Description:Set the write buffer size of the stream

Function name: stream_set_write_buffer()

Applicable version: PHP 4 >= 4.3.0, PHP 5, PHP 7

Function description: stream_set_write_buffer() function is used to set the write buffer size of the stream.

Syntax: bool stream_set_write_buffer ( resource $stream , int $buffer )

parameter:

  • stream: Required, indicating the stream resource to set the buffer size.
  • buffer: Required, indicating the buffer size to be set, in bytes. If buffer is 0, write buffering is disabled.

Return value: Return true if the buffer size is successfully set, otherwise return false.

Example:

 // 打开一个文件流$stream = fopen('example.txt', 'w'); // 设置写缓冲为8192 字节if (stream_set_write_buffer($stream, 8192)) { echo '写缓冲大小设置成功!'; } else { echo '写缓冲大小设置失败!'; } // 关闭文件流fclose($stream);

In the example above, we first use the fopen() function to open a file stream, and then use the stream_set_write_buffer() function to set the write buffer size to 8192 bytes. If the setting is successful, the output is "Write buffer size setting is successful!", otherwise the output is "Write buffer size setting is failed!". Finally, we use the fclose() function to close the file stream.

Notice:

  • When the buffer parameter is 0, write buffering is disabled.
  • The write buffer size can be set globally using the ini_set() function without calling the stream_set_write_buffer() function on each stream. For example: ini_set('default_socket_send_buffer', 8192);
Similar Functions
Popular Articles