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