Function name: stream_get_meta_data()
Function Description: stream_get_meta_data() function gets metadata related to the specified stream.
Applicable version: PHP 4 >= 4.3.0, PHP 5, PHP 7
Syntax: stream_get_meta_data(resource $stream): array
parameter:
Return value:
Example:
// 创建一个文件流$stream = fopen('file.txt', 'r'); // 获取流的元数据$metaData = stream_get_meta_data($stream); // 打印元数据print_r($metaData); // 关闭流fclose($stream);
Output result:
Array ( [wrapper_type] => plainfile [stream_type] => STDIO [mode] => r [unread_bytes] => 0 [seekable] => 1 [uri] => file.txt [timed_out] => [blocked] => 1 [eof] => )
In the example above, we first create a file stream through the fopen() function and assign it to the $stream variable. Then, we use the stream_get_meta_data() function to get the metadata of the stream and assign the returned associative array to the $metaData variable. Finally, we print out the contents of the metadata through the print_r() function.
The metadata in the output results contains some information about the stream, such as the type, pattern, whether it is readable and writeable, file path, etc.