• Register
4,670 points
9 5 1

 Php provides an efficient way of handling streams, it has different inbuilt functions with different functionalities or capabilities. Stream_get_meta_data function is a type of inbuilt PHP function used to information about streams or pointers, this information could be header or metadata.

Purpose and importance of Stream_get_meta_data ()

The purpose of using the Stream_get_meta_data function is that when we need to retrieve some information about streams, we will use this function. Let’s see how this function works in PHP?

Syntax and structure of Stream_get_meta_data ()


stream_get_meta_data ( resource $stream )

This function accepts only one parameter, and that parameter is $stream, or simply you can say stream about which want to get some metadata. The stream or metadata is actually created by one of the following functions “fopen (), fsockopen (), and pfsockopen ()”.

Does this function return value?

Yes, Stream_get_meta_data () has a return value which is an array. The returned array may contain the following items.

Timed_out: This is a Boolean item, which means it returns true if the given stream timed out.

Blocked: When the steam is enabled with blocking input/ output mode this Boolean item returns true.

Eof(bool): also known as the end of the file item. Eof is an optional item it comes true if the stream reaches at end file.

Unread_bytes: To display internal buffer information like the number of bytes a buffer is carrying at present.

Stream_type: an interesting item that specifies the way a stream will be implemented.

Wrapper_type: this item is used for the wrapper implementation layers to specify the protocol or to define the protocol for the wrapper implementation layer.

Wrapper_data: this is specific data that belongs to the steam.

Mode:  This item shows how the stream can be accessed, simply it specifies the method of access.

Seekable: these items come/ return true if the current stream is seekable. And Uri is an identifier provided by the user.


$url = 'http://www.kodlogs.com/';

if (!$fp = fopen($url, 'r')) {
    trigger_error("Unable to open URL ($url)", E_USER_ERROR);
//return the meta data 
$meta_data= stream_get_meta_data($fp);
// print the array




4,670 points
9 5 1