Function name: stream_set_chunk_size()
Applicable version: PHP 5.4.0 and above
Function description: stream_set_chunk_size() function is used to set the chunking size of a stream.
Syntax: bool stream_set_chunk_size(resource $stream, int $chunk_size)
parameter:
Return value: Return true if the chunking size is successfully set, otherwise return false.
Example:
// 打开一个文件流$stream = fopen('example.txt', 'r'); // 设置流的分块大小为1024 字节if (stream_set_chunk_size($stream, 1024)) { echo "成功设置分块大小为1024 字节"; } else { echo "设置分块大小失败"; } // 关闭文件流fclose($stream);
In the example above, we first use the fopen() function to open a file stream and assign it to the variable $stream. Then, we use the stream_set_chunk_size() function to set the chunking size of the stream to 1024 bytes. If the setting is successful, the output is "Successfully set the chunking size to 1024 bytes"; otherwise, the output is "Failed to set the chunking size". Finally, we use the fclose() function to close the file stream.
Note that the stream_set_chunk_size() function is only suitable for addressable streams (such as file streams) and is only available if the option to support chunked read is enabled at PHP compilation.