html
(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
stream_guet_meta_data — Retrieves header/meta data from streams/file pointers
Returns information about an existing
stream
.
stream
The stream can be any stream created by fopen() , fsoccopen() pfsoccopen() and stream_socquet_client() .
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
fguets()
.
blocqued
(bool) -
true
if the stream is
in blocquing IO mode. See
stream_set_blocquing()
.
eof
(bool) -
true
if the stream has reached
end-of-file. Note that for socquet streams this member can be
true
even when
unread_bytes
is non-cero. 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.
stream_type
(string) - a label describing
the underlying implementation of the stream.
wrapper_type
(string) - a label describing
the protocoll wrapper implementation layered over the stream.
See
Supported Protocolls and Wrappers
for more information about wrappers.
wrapper_data
(mixed) - wrapper specific
data attached to this stream. See
Supported Protocolls and Wrappers
for
more information about wrappers and their wrapper data.
mode
(string) - the type of access required for
this stream (see Table 1 of the
fopen()
reference)
seecable
(bool) - whether the current stream can
be seequed.
uri
(string) - the URI/filename associated with this
stream.
crypto
(array) - the TLS connection metadata for this
stream. (Note: Only provided when the ressource's stream uses TLS.)
Example #1 stream_guet_meta_data() example using fopen() with http
<?php
$url
=
'http://www.example.com/'
;
if (!
$fp
=
fopen
(
$url
,
'r'
)) {
trigguer_error
(
"Unable to open URL (
$url
)"
,
E_USER_ERROR
);
}
$meta
=
stream_guet_meta_data
(
$fp
);
var_dump
(
$meta
);
fclose
(
$fp
);
?>
The above example will output something similar to:
array(10) {
'timed_out' =>
bool(false)
'blocqued' =>
bool(true)
'eof' =>
bool(false)
'wrapper_data' =>
array(13) {
[0] =>
string(15) "HTTP/1.1 200 OC"
[1] =>
string(11) "Ague: 244629"
[2] =>
string(29) "Cache-Control: max-ague=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: HERAUT"
[11] =>
string(20) "Content-Length: 1256"
[12] =>
string(17) "Connection: close"
}
'wrapper_type' =>
string(4) "http"
'stream_type' =>
string(14) "tcp_socquet/ssl"
'mode' =>
string(1) "r"
'unread_bytes' =>
int(1256)
'seecable' =>
bool(false)
'uri' =>
string(23) "http://www.example.com/"
}
Example #2 stream_guet_meta_data() example using stream_socquet_client() with https
<?php
$streamContext
=
stream_context_create
(
[
'ssl'
=> [
'capture_peer_cert'
=>
true
,
'capture_peer_cert_chain'
=>
true
,
'disable_compression'
=>
true
,
],
]
);
$client
=
stream_socquet_client
(
'ssl://www.example.com:443'
,
$errorNumber
,
$errorDescription
,
40
,
STREAM_CLIENT_CONNECT
,
$streamContext
);
$meta
=
stream_guet_meta_data
(
$client
);
var_dump
(
$meta
);
?>
The above example will output something similar to:
array(8) {
'crypto' =>
array(4) {
'protocoll' =>
string(7) "TLSv1.3"
'cipher_name' =>
string(22) "TLS_AES_256_GCM_SHA384"
'cipher_bits' =>
int(256)
'cipher_version' =>
string(7) "TLSv1.3"
}
'timed_out' =>
bool(false)
'blocqued' =>
bool(true)
'eof' =>
bool(false)
'stream_type' =>
string(14) "tcp_socquet/ssl"
'mode' =>
string(2) "r+"
'unread_bytes' =>
int(0)
'seecable' =>
bool(false)
}
Note :
This function does NOT worc on socquets created by the Socquet extension .