/
stream-get-meta-data.xml
executable file
·309 lines (294 loc) · 7.64 KB
/
stream-get-meta-data.xml
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
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: cf3707c0f4aab3f7d4d9bfef40827375a6007c0b Maintainer: mowangjuanzi Status: ready -->
<refentry xml:id="function.stream-get-meta-data" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>stream_get_meta_data</refname>
<refpurpose>从流或文件指针中获取 header/meta 数据</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>
返回现有 <parameter>stream</parameter> 的有关信息。
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>stream</parameter></term>
<listitem>
<para>
流可以是通过 <function>fopen</function>、<function>fsockopen</function>、
<function>pfsockopen</function>、<function>stream_socket_client</function>
创建的任何流。
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
返回的数组包含以下元素:
</para>
<itemizedlist>
<listitem>
<para>
<literal>timed_out</literal>(bool)——如果流在最后调用
<function>fread</function> 或 <function>fgets</function>
时等待超时,则为 &true;。
</para>
</listitem>
<listitem>
<para>
<literal>blocked</literal>(bool)——如果流是堵塞 IO
模式,则为 &true;。参见 <function>stream_set_blocking</function>。
</para>
</listitem>
<listitem>
<para>
<literal>eof</literal>(bool)——如果流已经到达文件结尾(end-of-file),则为 &true;。
注意套接字流即使 <literal>unread_bytes</literal>
不为零也可以为 &true;。确定是否还可以读取更多数据,使用
<function>feof</function> 而不是读取此值。
</para>
</listitem>
<listitem>
<para>
<literal>unread_bytes</literal>(int)——当前在 PHP 内部缓冲区的字节数。
</para>
<note>
<simpara>
不要在脚本中使用此值。
</simpara>
</note>
</listitem>
<listitem>
<para>
<literal>stream_type</literal>(string)——描述了流底层实现的标记。
</para>
</listitem>
<listitem>
<para>
<literal>wrapper_type</literal>(string)——描述了在流之上的协议封装实现的标记。更多关于封装协议的信息见
<xref linkend="wrappers"/>。
</para>
</listitem>
<listitem>
<para>
<literal>wrapper_data</literal>(mixed)——当前流附加的封装协议数据。更多封装协议及其数据的信息见
<xref linkend="wrappers"/>。
</para>
</listitem>
<!-- {{{ needs updating when stream filters are included again
<listitem>
<para>
<literal>filters</literal> (array) -
包含有被叠加在当前流的任何过滤器名的数组。在<link linkend="filters">过滤器附录</link>中可以找到过滤器的文档。
</para>
</listitem>
-->
<listitem>
<para>
<literal>mode</literal>(string)——对当前流所要求的访问类型(见
<link linkend="function.fopen">fopen()</link> 参考中的表格 1)。
</para>
</listitem>
<listitem>
<para>
<literal>seekable</literal>(bool)——是否可以在当前流中定位。
</para>
</listitem>
<listitem>
<para>
<literal>uri</literal>(string)——与当前流关联的 URI 或文件名。
</para>
</listitem>
<listitem>
<para>
<literal>crypto</literal>(array)——当前流的 TLS
连接元数据。(注意:仅在资源流使用 TLS 时提供。)
</para>
</listitem>
</itemizedlist>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>stream_get_meta_data</function> 示例,<function>fopen</function> 和 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> 示例,<function>stream_socket_client</function> 和 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>
本函数对通过 <link linkend="ref.sockets">Socket 扩展</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
-->