Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

stream_get_meta_data

Description

The stream_get_meta_data of Stream for PHP retrieves header/meta data from streams/file pointers.

Syntax

stream_get_meta_data(
    resource $stream
): array

Parameters

stream

The stream can be any stream created by fopen(), fsockopen(), pfsockopen(), and stream_socket_client().

Return

The result array contains the following items:

ItemDescription
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.
wrapper_data (mixed)wrapper specific data attached to this stream. See Supported Protocols and Wrappers for more information about wrappers and their wrapper data.
wrapper_type (string)a label describing the protocol wrapper implementation layered over the stream. See Supported Protocols and Wrappers for more information about wrappers.
stream_type (string)a label describing the underlying implementation of the stream.
mode (string)the type of access required for this stream.
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.
seekable (bool)whether the current stream can be seeked.
uri (string)the URI/filename associated with this stream.

Examples

1 · stream · fopen

<?

$filename = "https://www.php.net/";
$mode = "r";

$stream = fopen($filename, $mode);

    $return = stream_get_meta_data($stream);

    print_r($return);

fclose($stream);

?>
Array
(
    [crypto] => Array
        (
            [protocol] => TLSv1.2
            [cipher_name] => ECDHE-ECDSA-AES128-GCM-SHA256
            [cipher_bits] => 128
            [cipher_version] => TLSv1.2
        )

    [timed_out] => 
    [blocked] => 1
    [eof] => 
    [wrapper_data] => Array
        (
            [0] => HTTP/1.1 200 OK
            [1] => Server: myracloud
            [2] => Date: Tue, 15 Oct 2024 10:19:48 GMT
            [3] => Content-Type: text/html; charset=utf-8
            [4] => Connection: close
            [5] => Last-Modified: Tue, 15 Oct 2024 10:10:09 GMT
            [6] => Content-language: en
            [7] => Permissions-Policy: interest-cohort=()
            [8] => X-Frame-Options: SAMEORIGIN
            [9] => Set-Cookie: COUNTRY=NA%2C80.90.5.137; expires=Tue, 22 Oct 2024 10:19:47 GMT; Max-Age=604800; path=/; domain=.php.net
            [10] => Set-Cookie: LAST_NEWS=1728987587; expires=Wed, 15 Oct 2025 10:19:47 GMT; Max-Age=31536000; path=/; domain=.php.net
            [11] => Link: <https://www.php.net/index>; rel=shorturl
            [12] => Expires: Tue, 15 Oct 2024 10:19:48 GMT
            [13] => Cache-Control: max-age=0
        )

    [wrapper_type] => http
    [stream_type] => tcp_socket/ssl
    [mode] => r
    [unread_bytes] => 7538
    [seekable] => 
    [uri] => https://www.php.net/
)

2 · stream · stream_socket_client

<?

$address = "ssl://osbo.com:443";

$stream = stream_socket_client($address);

$return = stream_get_meta_data($stream);

print_r($return);

?>
Array
(
    [crypto] => Array
        (
            [protocol] => TLSv1.3
            [cipher_name] => TLS_AES_256_GCM_SHA384
            [cipher_bits] => 256
            [cipher_version] => TLSv1.3
        )

    [timed_out] => 
    [blocked] => 1
    [eof] => 
    [stream_type] => tcp_socket/ssl
    [mode] => r+
    [unread_bytes] => 0
    [seekable] => 
    [uri] => ssl://osbo.com:443
)
HomeMenu