1--TEST--
2Testing stream_get_meta_data() "eof" field on a udp socket
3--FILE--
4<?php
5
6/* Setup socket server */
7$server = stream_socket_server('tcp://127.0.0.1:31334');
8
9/* Connect to it */
10$client = fsockopen('tcp://127.0.0.1:31334');
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:\n";
23fgets($client);
24var_dump(stream_get_meta_data($client));
25
26echo "\n\nClose the server side socket and read the remaining data from the client:\n";
27fclose($socket);
28fclose($server);
29while(!feof($client)) {
30    fread($client, 1);
31}
32var_dump(stream_get_meta_data($client));
33
34fclose($client);
35
36?>
37--EXPECTF--
38Write some data:
39array(8) {
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(%i)
52  ["seekable"]=>
53  bool(false)
54  ["uri"]=>
55  string(21) "tcp://127.0.0.1:31334"
56}
57
58
59Read a line from the client:
60array(8) {
61  ["timed_out"]=>
62  bool(false)
63  ["blocked"]=>
64  bool(true)
65  ["eof"]=>
66  bool(false)
67  ["stream_type"]=>
68  string(%d) "tcp_socke%s"
69  ["mode"]=>
70  string(2) "r+"
71  ["unread_bytes"]=>
72  int(%i)
73  ["seekable"]=>
74  bool(false)
75  ["uri"]=>
76  string(21) "tcp://127.0.0.1:31334"
77}
78
79
80Close the server side socket and read the remaining data from the client:
81array(8) {
82  ["timed_out"]=>
83  bool(false)
84  ["blocked"]=>
85  bool(true)
86  ["eof"]=>
87  bool(true)
88  ["stream_type"]=>
89  string(%d) "tcp_socke%s"
90  ["mode"]=>
91  string(2) "r+"
92  ["unread_bytes"]=>
93  int(%i)
94  ["seekable"]=>
95  bool(false)
96  ["uri"]=>
97  string(21) "tcp://127.0.0.1:31334"
98}
99