PHP set_file_buffer()Functions


PHP Filesystem 参考手册Complete PHP Filesystem Reference Manual

Definition and Usage

The set_file_buffer() function sets the buffer size of an open file.

When using the fwrite() function to output results, the buffer size is usually 8K. Therefore, if two processes are writing to the same file, each file can only be written up to 8K at a time, allowing other processes to write. If buffer is 0, then write operations will not be buffered (this means: other processes are only allowed to write after the first writing process has completely finished).

If successful, the function returns 0; otherwise, it returns EOF.

Syntax

set_file_buffer(file,buffer)

Parameter Description
file Required. Specifies the open file.
buffer Required. Specifies the buffer size in bytes.


Tips and Notes

Tip:This function is an alias of stream_set_write_buffer().


Examples

Create an unbuffered stream:

<?php
$file = fopen("test.txt","w");
if ($file)
{
set_file_buffer($file,0);
fwrite($file,"Hello World. Testing!");
fclose($file);
}
?>


PHP Filesystem 参考手册Complete PHP Filesystem Reference Manual Other Extensions