mirror of
https://github.com/php/doc-en.git
synced 2026-04-28 09:43:18 +02:00
cf3707c0f4
This adds both examples and the missing optional key-value pair for the return array. Also switches to `var_dump` instead of `print_r`. Co-authored-by: George Peter Banyard <girgias@php.net> Closes GH-1124.
318 lines
7.7 KiB
XML
318 lines
7.7 KiB
XML
<?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
|
|
-->
|