Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is stream and stream wrapper in php

Tags:

file

php

stream

For my understanding of streams in PHP, a stream is an interface that provides methods for
reading from and writing to a resource and this interface is implemented by different
types of stream wrappers (http,ftp,file etc) for providing specific functionality. So when we say fopen() opens up stream, does it mean instantiation of a specific stream
wrapper object? Please clarify me if i am wrong
Thanks

like image 298
user1227541 Avatar asked Jun 27 '12 12:06

user1227541


People also ask

What is a stream wrapper PHP?

Introduction ¶ A wrapper is additional code which tells the stream how to handle specific protocols/encodings. For example, the http wrapper knows how to translate a URL into an HTTP/1.0 request for a file on a remote server.

What is a stream in PHP?

PHP Stream Introduction Streams are the way of generalizing file, network, data compression, and other operations which share a common set of functions and uses. In its simplest definition, a stream is a resource object which exhibits streamable behavior.

What is a protocol in PHP?

The PHP HTTP(Hyper Text Transfer Protocol) functions allow us to handle the information which is sent to the browser by the web server. The purpose of the HTTP extension is to provide comfort and robust set of functionality for major applications.


1 Answers

Not all streams are implemented at that level, most built-ins are at C level, so no, as far as PHP is concerned not a streamwrapper object. That interface makes sure it works like a stream, not the other way around. (In essence: all streamwrappers can be accessed like a stream resource, but not all stream resources are provided by streamwrapper classes). You can however override for instance the file:/// wrapper and other built-ins, great fun.

like image 191
Wrikken Avatar answered Oct 16 '22 06:10

Wrikken