PHP stream_get_meta_data() Function
The PHP stream_get_meta_data() function returns information about an existing stream.
Syntax
stream_get_meta_data(stream)
Parameters
stream |
Required. Specify the stream. It can be any stream created by fopen(), fsockopen() and pfsockopen(). |
Return Value
Returns the result array contains the following items:
- timed_out (bool) - true if the stream timed out while waiting for data on the last call to fread() and fgets().
- blocked (bool) - true if the stream is in blocking IO mode. See stream_set_blocking() function for more detail.
- eof (bool) - true if the stream has reached end-of-file.
- unread_bytes (int) - the number of bytes currently contained in the PHP's own internal buffer.
- stream_type (string) - a label describing the underlying implementation of the stream.
- wrapper_type (string) - a label describing the protocol wrapper implementation layered over the stream.
- wrapper_data (mixed) - wrapper specific data attached to this stream.
- mode (string) - the type of access required for this stream.
- seekable (bool) - whether the current stream can be seeked.
- uri (string) - the URI/filename associated with this stream.
Example:
The example below shows the usage of stream_get_meta_data() function.
<?php $url = 'http://www.example.com/'; if (!$fp = fopen($url, 'r')) { trigger_error("Unable to open URL ($url)", E_USER_ERROR); } $meta = stream_get_meta_data($fp); print_r($meta); fclose($fp); ?>
The output of the above code will be similar to:
Array ( [timed_out] => [blocked] => 1 [eof] => [wrapper_data] => Array ( [0] => HTTP/1.1 200 OK [1] => Age: 482058 [2] => Cache-Control: max-age=604800 [3] => Content-Type: text/html; charset=UTF-8 [4] => Date: Sun, 24 Oct 2021 04:57:08 GMT [5] => Etag: "3147526947+ident" [6] => Expires: Sun, 31 Oct 2021 04:57:08 GMT [7] => Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT [8] => Server: ECS (dna/63B4) [9] => Vary: Accept-Encoding [10] => X-Cache: HIT [11] => Content-Length: 1256 [12] => Connection: close ) [wrapper_type] => http [stream_type] => tcp_socket/ssl [mode] => r [unread_bytes] => 1256 [seekable] => [uri] => http://www.example.com/ )
❮ PHP Streams Reference