stream_get_meta_data()
stream_get_meta_data() — Retrieves header/meta data from streams/file pointers.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
Signature
stream_get_meta_data(resource $stream): array
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $stream | resource | The stream can be any stream created by fopen(), fsockopen() pfsockopen() and stream_socket_client(). |
Return value
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 be true 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. You shouldn't use this value in a script. stream_type (string) - a label ...
Example
A runnable snippet:
$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); var_dump($meta); fclose($fp);
Output:
array(10) { 'timed_out' => bool(false) 'blocked' => bool(true) 'eof' => bool(false) 'wrapper_data' => array(13) { [0] => string(15) "HTTP/1.1 200 OK" [1] => string(11) "Age: 244629" [2] => string(29) "Cache-Control: max-age=604800" [3] => string(38) "Content-Type: text/html; charset=UTF-8" [4] => string(35) "Date: Sat, 20 Nov 2021 18:17:57 GMT" [5] => string(24) "Etag: "3147526947+ident"" [6] => string(38) "Expires: Sat, 27 Nov 2021 18:17:57 GMT" [7] => string(44) "Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT" [8] => string(22) "Server: ECS (chb/0286)" [9] => string(21) "Vary: Accept-Encoding" [10] => string(12) "X-Cache: HIT" [11] => string(20) "Content-Length: 1256" [12] => string(17) "Connection: close" } 'wrapper_type' => string(4) "http" 'stream_type' => string(14) "tcp_socket/ssl" 'mode' => string(1) "r" 'unread_bytes' => int(1256) 'seekable' => bool(false) 'uri' => string(23) "http://www.example.com/" }
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page stream_get_meta_data() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.