1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
|
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.stream-get-meta-data" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>stream_get_meta_data</refname>
<refpurpose>Retrieves header/meta data from streams/file pointers</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>array</type><methodname>stream_get_meta_data</methodname>
<methodparam><type>resource</type><parameter>stream</parameter></methodparam>
</methodsynopsis>
<para>
Returns information about an existing <parameter>stream</parameter>.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>stream</parameter></term>
<listitem>
<para>
The stream can be any stream created by <function>fopen</function>,
<function>fsockopen</function> <function>pfsockopen</function> and <function>stream_socket_client</function>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
The result array contains the following items:
</para>
<itemizedlist>
<listitem>
<para>
<literal>timed_out</literal> (bool) - &true; if the stream
timed out while waiting for data on the last call to
<function>fread</function> or <function>fgets</function>.
</para>
</listitem>
<listitem>
<para>
<literal>blocked</literal> (bool) - &true; if the stream is
in blocking IO mode. See <function>stream_set_blocking</function>.
</para>
</listitem>
<listitem>
<para>
<literal>eof</literal> (bool) - &true; if the stream has reached
end-of-file. Note that for socket streams this member can be &true;
even when <literal>unread_bytes</literal> is non-zero. To
determine if there is more data to be read, use
<function>feof</function> instead of reading this item.
</para>
</listitem>
<listitem>
<para>
<literal>unread_bytes</literal> (int) - the number of bytes
currently contained in the PHP's own internal buffer.
</para>
<note>
<simpara>
You shouldn't use this value in a script.
</simpara>
</note>
</listitem>
<listitem>
<para>
<literal>stream_type</literal> (string) - a label describing
the underlying implementation of the stream.
</para>
</listitem>
<listitem>
<para>
<literal>wrapper_type</literal> (string) - a label describing
the protocol wrapper implementation layered over the stream.
See <xref linkend="wrappers"/> for more information about wrappers.
</para>
</listitem>
<listitem>
<para>
<literal>wrapper_data</literal> (mixed) - wrapper specific
data attached to this stream. See <xref linkend="wrappers"/> for
more information about wrappers and their wrapper data.
</para>
</listitem>
<!-- {{{ needs updating when stream filters are included again
<listitem>
<para>
<literal>filters</literal> (array) - and array containing
the names of any filters that have been stacked onto this stream.
Documentation on filters can be found in the
<link linkend="filters">Filters appendix</link>.
</para>
</listitem>
-->
<listitem>
<para>
<literal>mode</literal> (string) - the type of access required for
this stream (see Table 1 of the <link
linkend="function.fopen">fopen()</link> reference)
</para>
</listitem>
<listitem>
<para>
<literal>seekable</literal> (bool) - whether the current stream can
be seeked.
</para>
</listitem>
<listitem>
<para>
<literal>uri</literal> (string) - the URI/filename associated with this
stream.
</para>
</listitem>
<listitem>
<para>
<literal>crypto</literal> (array) - the TLS connection metadata for this
stream. (Note: Only provided when the resource's stream uses TLS.)
</para>
</listitem>
</itemizedlist>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>stream_get_meta_data</function> example using <function>fopen</function> with http</title>
<programlisting role="php">
<![CDATA[
<?php
$url = 'http://www.example.com/';
if (!$fp = fopen($url, 'r')) {
trigger_error("Unable to open URL ($url)", E_USER_ERROR);
}
$meta = stream_get_meta_data($fp);
var_dump($meta);
fclose($fp);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
array(10) {
'timed_out' =>
bool(false)
'blocked' =>
bool(true)
'eof' =>
bool(false)
'wrapper_data' =>
array(13) {
[0] =>
string(15) "HTTP/1.1 200 OK"
[1] =>
string(11) "Age: 244629"
[2] =>
string(29) "Cache-Control: max-age=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: HIT"
[11] =>
string(20) "Content-Length: 1256"
[12] =>
string(17) "Connection: close"
}
'wrapper_type' =>
string(4) "http"
'stream_type' =>
string(14) "tcp_socket/ssl"
'mode' =>
string(1) "r"
'unread_bytes' =>
int(1256)
'seekable' =>
bool(false)
'uri' =>
string(23) "http://www.example.com/"
}
]]>
</screen>
</example>
<example>
<title><function>stream_get_meta_data</function> example using <function>stream_socket_client</function> with https</title>
<programlisting role="php">
<![CDATA[
<?php
$streamContext = stream_context_create(
[
'ssl' => [
'capture_peer_cert' => true,
'capture_peer_cert_chain' => true,
'disable_compression' => true,
],
]
);
$client = stream_socket_client(
'ssl://www.example.com:443',
$errorNumber,
$errorDescription,
40,
STREAM_CLIENT_CONNECT,
$streamContext
);
$meta = stream_get_meta_data($client);
var_dump($meta);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
array(8) {
'crypto' =>
array(4) {
'protocol' =>
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)
'blocked' =>
bool(true)
'eof' =>
bool(false)
'stream_type' =>
string(14) "tcp_socket/ssl"
'mode' =>
string(2) "r+"
'unread_bytes' =>
int(0)
'seekable' =>
bool(false)
}
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<note>
<para>This function does NOT work on sockets created by the <link
linkend="ref.sockets">Socket extension</link>.
</para>
</note>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>get_headers</function></member>
<member><link linkend="reserved.variables.httpresponseheader">$http_response_header</link></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
|