stream_get_meta_data()函数是PHP中的内置函数,用于从流/文件指针获取标头或元数据。
用法:
array stream_get_meta_data( $stream )
参数:该函数接受单个参数$stream,该参数指定要检索的元数据,并由任何函数fopen(),fsockopen()和pfsockopen()创建。
返回值:此函数返回一个包含以下项的数组:
- timed_out:这是布尔类型的项目,如果流超时,则为TRUE。
 - blocked:它是布尔类型的项目,如果流处于阻塞IO模式,则为True。
 - eof(bool):它是可选的。如果流到达文件末尾,则为True。
 - unread_bytes:内部缓冲区中的字节数。
 - stream_type:它用于指定流的实现。
 - wrapper_type:它用于指定协议包装器实现层。
 - wrapper_data:它是附加到此流的特定数据。
 - mode: 这是此流所需的访问类型。
 - seekable:当当前流寻找时,这是真的。
 - uri:用户提供的格式错误的资源标识符。
 
以下示例程序旨在说明PHP中的stream_get_meta_data()函数:
程序1:
<?php 
  
// PHP program to illustrate 
// stream_get_meta_data function 
  
$url = 'http://php.net/manual/en/function.stream-get-meta-data.php'; 
  
$file = fopen($url, 'r'); 
$meta_data = stream_get_meta_data($file); 
  
print_r($meta_data); 
  
fclose($file); 
  
?>
输出:
Array
(
    [timed_out] => 
    [blocked] => 1
    [eof] => 
    [wrapper_data] => Array
        (
            [0] => HTTP/1.1 200 OK
            [1] => Server: nginx/1.10.3
            [2] => Date: Mon, 17 Dec 2018 11:04:39 GMT
            [3] => Content-Type: text/html; charset=utf-8
            [4] => Connection: close
            [5] => Content-language: en
            [6] => X-Frame-Options: SAMEORIGIN
            [7] => Set-Cookie: LAST_LANG=en; expires=Tue, 17-Dec-2019 11:04:39 GMT; Max-Age=31536000; path=/; domain=.php.net
            [8] => Set-Cookie: COUNTRY=NA%2C54.201.119.186; expires=Mon, 24-Dec-2018 11:04:39 GMT; Max-Age=604800; path=/; domain=.php.net
            [9] => Link: ; rel=shorturl
            [10] => Last-Modified: Mon, 17 Dec 2018 05:06:18 GMT
            [11] => Vary: Accept-Encoding
        )
    [wrapper_type] => http
    [stream_type] => tcp_socket/ssl
    [mode] => r
    [unread_bytes] => 7647
    [seekable] => 
    [uri] => http://php.net/manual/en/function.stream-get-meta-data.php
)
程序2:程序通过函数打印返回数组的长度。
<?php 
  
// PHP program to illustrate  
// stream_get_meta_data function 
  
// url to be open using fopen 
$url = 'http://www.php.net/news.rss'; 
  
// checking is url openable or not 
if (!$fp = fopen($url, 'r')) { 
    trigger_error("Unable to open URL ($url)", E_USER_ERROR); 
} 
  
$fp = fopen($url, 'r'); 
  
$meta_data = stream_get_meta_data($fp); 
  
print(sizeof($meta_data)); 
  
fclose($fp); 
?>
输出:
10
参考: http://php.net/manual/en/function.stream-get-meta-data.php
相关用法
- PHP abs()用法及代码示例
 - PHP end()用法及代码示例
 - d3.js d3.map.set()用法及代码示例
 - PHP each()用法及代码示例
 - PHP Ds\Map xor()用法及代码示例
 - CSS var()用法及代码示例
 - d3.js d3.set.has()用法及代码示例
 - PHP sin( )用法及代码示例
 - PHP Ds\Map put()用法及代码示例
 - p5.js nfs()用法及代码示例
 - p5.js int()用法及代码示例
 - PHP pos()用法及代码示例
 
注:本文由纯净天空筛选整理自R_Raj大神的英文原创作品 PHP | stream_get_meta_data() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
