1--TEST--
2Testing stream_get_meta_data() "timed_out" field on a udp socket
3--FILE--
4<?php
5
6/* Setup socket server */
7$server = stream_socket_server('tcp://127.0.0.1:31332');
8
9/* Connect to it */
10$client = fsockopen('tcp://127.0.0.1:31332');
11if (!$client) {
12    die("Unable to create socket");
13}
14
15/* Accept that connection */
16$socket = stream_socket_accept($server);
17
18var_dump(stream_get_meta_data($client));
19
20echo "\n\nSet a timeout on the client and attempt a read:\n";
21socket_set_timeout($client, 0, 1000);
22fread($client, 1);
23var_dump(stream_get_meta_data($client));
24
25echo "\n\nWrite some data from the server:\n";
26fwrite($socket, "12345");
27var_dump(stream_get_meta_data($client));
28
29echo "\n\nRead some data from the client:\n";
30fread($client, 5);
31var_dump(stream_get_meta_data($client));
32
33fclose($client);
34fclose($socket);
35fclose($server);
36
37?>
38--EXPECTF--
39array(7) {
40  ["timed_out"]=>
41  bool(false)
42  ["blocked"]=>
43  bool(true)
44  ["eof"]=>
45  bool(false)
46  ["stream_type"]=>
47  string(%d) "tcp_socke%s"
48  ["mode"]=>
49  string(2) "r+"
50  ["unread_bytes"]=>
51  int(0)
52  ["seekable"]=>
53  bool(false)
54}
55
56
57Set a timeout on the client and attempt a read:
58array(7) {
59  ["timed_out"]=>
60  bool(true)
61  ["blocked"]=>
62  bool(true)
63  ["eof"]=>
64  bool(false)
65  ["stream_type"]=>
66  string(%d) "tcp_socke%s"
67  ["mode"]=>
68  string(2) "r+"
69  ["unread_bytes"]=>
70  int(0)
71  ["seekable"]=>
72  bool(false)
73}
74
75
76Write some data from the server:
77array(7) {
78  ["timed_out"]=>
79  bool(true)
80  ["blocked"]=>
81  bool(true)
82  ["eof"]=>
83  bool(false)
84  ["stream_type"]=>
85  string(%d) "tcp_socke%s"
86  ["mode"]=>
87  string(2) "r+"
88  ["unread_bytes"]=>
89  int(0)
90  ["seekable"]=>
91  bool(false)
92}
93
94
95Read some data from the client:
96array(7) {
97  ["timed_out"]=>
98  bool(false)
99  ["blocked"]=>
100  bool(true)
101  ["eof"]=>
102  bool(false)
103  ["stream_type"]=>
104  string(%d) "tcp_socke%s"
105  ["mode"]=>
106  string(2) "r+"
107  ["unread_bytes"]=>
108  int(0)
109  ["seekable"]=>
110  bool(false)
111}
112