1--TEST--
2fgets() with a socket stream
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--FILE--
6<?php
7
8/* Setup socket server */
9$server = stream_socket_server('tcp://127.0.0.1:31337');
10
11/* Connect to it */
12$client = fsockopen('tcp://127.0.0.1:31337');
13
14if (!$client) {
15	die("Unable to create socket");
16}
17
18/* Accept that connection */
19$socket = stream_socket_accept($server);
20
21echo "Write some data:\n";
22fwrite($socket, "line1\nline2\nline3\n");
23
24
25echo "\n\nRead a line from the client:\n";
26var_dump(fgets($client));
27
28echo "\n\nRead another line from the client:\n";
29var_dump(fgets($client));
30
31echo "\n\nClose the server side socket and read the remaining data from the client\n";
32fclose($socket);
33fclose($server);
34while(!feof($client)) {
35	fread($client, 1);
36}
37
38echo "done\n";
39
40?>
41--EXPECT--
42Write some data:
43
44
45Read a line from the client:
46string(6) "line1
47"
48
49
50Read another line from the client:
51string(6) "line2
52"
53
54
55Close the server side socket and read the remaining data from the client
56done
57