PHP 网络函数

PHP socket_get_status() 函数返回有关现有流的信息。此函数是 stream_get_meta_data() 函数的别名。

语法

socket_get_status(stream) 

参数

stream必填。 指定流。它可以是由 fopen() 创建的任何流,fsockopen()pfsockopen()

返回值

返回包含以下项目的结果数组:

  • timed_out (bool) - 如果流在等待数据时超时,则为 true最后一次调用 fread() 和 fgets().
  • blocked (bool) - 如果流处于阻塞 IO 模式,则为 true。有关更多详细信息,请参阅 socket_set_blocking() 函数。
  • eof (bool) - true if流已到达文件末尾。
  • unread_bytes (int) - PHP 自己的内部缓冲区中当前包含的字节数。
  • stream_type (string) - 描述的标签流的底层实现。
  • wrapper_type(字符串)- 描述流上分层的协议包装器实现的标签。
  • wrapper_data(混合)- 附加到该流的包装器特定数据.
  • mode(字符串)- 此流所需的访问类型。
  • seekable(布尔)- 是否可以查找当前流。
  • uri (字符串)- 与此流关联的 URI/文件名。

示例:

下面的示例显示了 socket_get_status() 的用法功能。

<?php
$url = 'http://www.example.com/';

if (!$fp = fopen($url, 'r')) {
  trigger_error("Unable to open URL ($url)", E_USER_ERROR);
}

$meta = socket_get_status($fp);

print_r($meta);

fclose($fp);
?> 

上述代码的输出将类似于:

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/
)