stream_get_meta_data
(PHP 4 >= 4.3.0, PHP 5, PHP 7)
stream_get_meta_data — Retrieves header/meta data from streams/file pointers
Description
$stream
) : array
Returns information about an existing stream
.
Return Values
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() or fgets(). -
blocked (bool) -
TRUE
if the stream is in blocking IO mode. See stream_set_blocking(). -
eof (bool) -
TRUE
if the stream has reached end-of-file. Note that for socket streams this member can beTRUE
even when unread_bytes is non-zero. To determine if there is more data to be read, use feof() instead of reading this item. -
unread_bytes (int) - the number of bytes currently contained in the PHP's own internal buffer.
Note: You shouldn't use this value in a script.
-
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. See Supported Protocols and Wrappers for more information about wrappers.
-
wrapper_data (mixed) - wrapper specific data attached to this stream. See Supported Protocols and Wrappers for more information about wrappers and their wrapper data.
-
mode (string) - the type of access required for this stream (see Table 1 of the fopen() reference)
-
seekable (bool) - whether the current stream can be seeked.
-
uri (string) - the URI/filename associated with this stream.
Examples
Example #1 stream_get_meta_data() example
<?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 above example will output something similar to:
Array ( [wrapper_data] => Array ( [0] => HTTP/1.1 200 OK [1] => Server: Apache/2.2.3 (Red Hat) [2] => Last-Modified: Tue, 15 Nov 2005 13:24:10 GMT [3] => ETag: "b300b4-1b6-4059a80bfd280" [4] => Accept-Ranges: bytes [5] => Content-Type: text/html; charset=UTF-8 [6] => Set-Cookie: FOO=BAR; expires=Fri, 21-Dec-2012 12:00:00 GMT; path=/; domain=.example.com [6] => Connection: close [7] => Date: Fri, 16 Oct 2009 12:00:00 GMT [8] => Age: 1164 [9] => Content-Length: 438 ) [wrapper_type] => http [stream_type] => tcp_socket/ssl [mode] => r [unread_bytes] => 438 [seekable] => [uri] => http://www.example.com/ [timed_out] => [blocked] => 1 [eof] => )
See Also
- get_headers() - Fetches all the headers sent by the server in response to an HTTP request
- $http_response_header
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-stream-get-meta-data.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.