Stream¶
Streams are a generalisation of the notion of files. Just like files, they can be opened, read, written and closed.
Unlike files, they may be a lot of things : archive, compressed data, sockets, other programs, etc. They also may not support all the range of features of files.
PHP offers native functions to create, configure, filter streams and process their data.
Streams may be extended with the notion of wrapper and protocols.
<?php
if ($stream = fopen('https://www.php.net', 'r')) {
// print the first 100 chars of the HTML page.
echo stream_get_contents($stream, -1, 100);
fclose($stream);
}
?>
Related : Abstraction Layer, Stream Wrapper, Stream Wrapper
Added in PHP 5.0