PHP Function Reference

PHP stream_set_chunk_size() Function



The PHP stream_set_chunk_size() function is used to set the stream chunk size.

Syntax

stream_set_chunk_size(stream, size)

Parameters


Parameters

stream Required. Specify the target stream.
size Required. Specify the desired new chunk size.

Return Value

Returns the previous chunk size on success. Returns false if size is less than 1 or greater than PHP_INT_MAX.

Exceptions

Emits an E_WARNING level error if size is less than 1 or greater than PHP_INT_MAX.

Example: stream_set_chunk_size() example

In the example below, stream_set_chunk_size() function is used to set the stream chunk size.

<?php
$file = "test.txt";

//open the file in write mode
$stream = fopen($file, 'w');

//getting the previous chunk size and
//setting the new chunk size to 2000
$prev_chunk_size = stream_set_chunk_size($stream, 2000);
echo "Previous chunk size: $prev_chunk_size bytes";

//closing the stream
fclose($stream);
?>

The output of the above code will be:

Previous chunk size: 8192 bytes

❮ PHP Streams Reference