Stream Wrapper¶
A stream wrapper is additional code which tells the stream how to handle specific protocols and encodings.
PHP supports several wrappers natively, in particular file://, http://, ftp://, php://, zlib://, data://, glob://, phar://, ssh2://, rar://, ogg:// and expect://.
Customs wrappers may be registered with stream_wrapper_register(). A wrapper may write in any kind of format.
<?php
// opening a file with the file wrapper
$fp = fopen('file://tmp/myfile.txt', 'r+');
// opening a file with the ftp wrapper
$fp = fopen('ftp://user:password@example.com/pub/file.txt', 'r+');
// opening a file with the phar wrapper
$fp = fopen('phar://someFile.txt', 'r+');
?>
See also A Guide to Streams in PHP: In-Depth Tutorial With Examples, Supported Protocols and Wrappers, stream_wrapper_register() and Example class registered as stream wrapper.