reference/stream/functions/stream-get-meta-data.xml
cf3707c0f4aab3f7d4d9bfef40827375a6007c0b
...
...
@@ -25,7 +25,7 @@
25
25
<listitem>
26
26
<para>
27
27
The stream can be any stream created by <function>fopen</function>,
28
-
<function>fsockopen</function> and <function>pfsockopen</function>.
28
+
<function>fsockopen</function> <function>pfsockopen</function> and <function>stream_socket_client</function>.
29
29
</para>
30
30
</listitem>
31
31
</varlistentry>
...
...
@@ -121,6 +121,12 @@
121
121
stream.
122
122
</para>
123
123
</listitem>
124
+
<listitem>
125
+
<para>
126
+
<literal>crypto</literal> (array) - the TLS connection metadata for this
127
+
stream. (Note: Only provided when the resource's stream uses TLS.)
128
+
</para>
129
+
</listitem>
124
130
</itemizedlist>
125
131
</refsect1>
126
132

...
...
@@ -128,7 +134,7 @@
128
134
&reftitle.examples;
129
135
<para>
130
136
<example>
131
-
<title><function>stream_get_meta_data</function> example</title>
137
+
<title><function>stream_get_meta_data</function> example using <function>fopen</function> with http</title>
132
138
<programlisting role="php">
133
139
<![CDATA[
134
140
<?php
...
...
@@ -140,7 +146,7 @@ if (!$fp = fopen($url, 'r')) {
140
146

141
147
$meta = stream_get_meta_data($fp);
142
148

143
-
print_r($meta);
149
+
var_dump($meta);
144
150

145
151
fclose($fp);
146
152
?>
...
...
@@ -149,33 +155,119 @@ fclose($fp);
149
155
&example.outputs.similar;
150
156
<screen>
151
157
<![CDATA[
152
-
Array
153
-
(
154
-
[wrapper_data] => Array
155
-
(
156
-
[0] => HTTP/1.1 200 OK
157
-
[1] => Server: Apache/2.2.3 (Red Hat)
158
-
[2] => Last-Modified: Tue, 15 Nov 2005 13:24:10 GMT
159
-
[3] => ETag: "b300b4-1b6-4059a80bfd280"
160
-
[4] => Accept-Ranges: bytes
161
-
[5] => Content-Type: text/html; charset=UTF-8
162
-
[6] => Set-Cookie: FOO=BAR; expires=Fri, 21-Dec-2012 12:00:00 GMT; path=/; domain=.example.com
163
-
[6] => Connection: close
164
-
[7] => Date: Fri, 16 Oct 2009 12:00:00 GMT
165
-
[8] => Age: 1164
166
-
[9] => Content-Length: 438
167
-
)
158
+
array(10) {
159
+
'timed_out' =>
160
+
bool(false)
161
+
'blocked' =>
162
+
bool(true)
163
+
'eof' =>
164
+
bool(false)
165
+
'wrapper_data' =>
166
+
array(13) {
167
+
[0] =>
168
+
string(15) "HTTP/1.1 200 OK"
169
+
[1] =>
170
+
string(11) "Age: 244629"
171
+
[2] =>
172
+
string(29) "Cache-Control: max-age=604800"
173
+
[3] =>
174
+
string(38) "Content-Type: text/html; charset=UTF-8"
175
+
[4] =>
176
+
string(35) "Date: Sat, 20 Nov 2021 18:17:57 GMT"
177
+
[5] =>
178
+
string(24) "Etag: "3147526947+ident""
179
+
[6] =>
180
+
string(38) "Expires: Sat, 27 Nov 2021 18:17:57 GMT"
181
+
[7] =>
182
+
string(44) "Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT"
183
+
[8] =>
184
+
string(22) "Server: ECS (chb/0286)"
185
+
[9] =>
186
+
string(21) "Vary: Accept-Encoding"
187
+
[10] =>
188
+
string(12) "X-Cache: HIT"
189
+
[11] =>
190
+
string(20) "Content-Length: 1256"
191
+
[12] =>
192
+
string(17) "Connection: close"
193
+
}
194
+
'wrapper_type' =>
195
+
string(4) "http"
196
+
'stream_type' =>
197
+
string(14) "tcp_socket/ssl"
198
+
'mode' =>
199
+
string(1) "r"
200
+
'unread_bytes' =>
201
+
int(1256)
202
+
'seekable' =>
203
+
bool(false)
204
+
'uri' =>
205
+
string(23) "http://www.example.com/"
206
+
}
207
+
]]>
208
+
</screen>
209
+
</example>
210
+
<example>
211
+
<title><function>stream_get_meta_data</function> example using <function>stream_socket_client</function> with https</title>
212
+
<programlisting role="php">
213
+
<![CDATA[
214
+
<?php
215
+
$streamContext = stream_context_create(
216
+
[
217
+
'ssl' => [
218
+
'capture_peer_cert' => true,
219
+
'capture_peer_cert_chain' => true,
220
+
'disable_compression' => true,
221
+
],
222
+
]
223
+
);
224
+

225
+
$client = stream_socket_client(
226
+
'ssl://www.example.com:443',
227
+
$errorNumber,
228
+
$errorDescription,
229
+
40,
230
+
STREAM_CLIENT_CONNECT,
231
+
$streamContext
232
+
);
233
+

168
234

169
-
[wrapper_type] => http
170
-
[stream_type] => tcp_socket/ssl
171
-
[mode] => r
172
-
[unread_bytes] => 438
173
-
[seekable] =>
174
-
[uri] => http://www.example.com/
175
-
[timed_out] =>
176
-
[blocked] => 1
177
-
[eof] =>
178
-
)
235
+
$meta = stream_get_meta_data($client);
236
+

237
+
var_dump($meta);
238
+
?>
239
+
]]>
240
+
</programlisting>
241
+
&example.outputs.similar;
242
+
<screen>
243
+
<![CDATA[
244
+
array(8) {
245
+
'crypto' =>
246
+
array(4) {
247
+
'protocol' =>
248
+
string(7) "TLSv1.3"
249
+
'cipher_name' =>
250
+
string(22) "TLS_AES_256_GCM_SHA384"
251
+
'cipher_bits' =>
252
+
int(256)
253
+
'cipher_version' =>
254
+
string(7) "TLSv1.3"
255
+
}
256
+
'timed_out' =>
257
+
bool(false)
258
+
'blocked' =>
259
+
bool(true)
260
+
'eof' =>
261
+
bool(false)
262
+
'stream_type' =>
263
+
string(14) "tcp_socket/ssl"
264
+
'mode' =>
265
+
string(2) "r+"
266
+
'unread_bytes' =>
267
+
int(0)
268
+
'seekable' =>
269
+
bool(false)
270
+
}
179
271
]]>
180
272
</screen>
181
273
</example>
182
274