Annotation of embedaddon/php/ext/standard/tests/file/fgets_socket_variation2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: fgets() over a socket with more than a buffer's worth of data
3: --CREDITS--
4: Dave Kelsey <d_kelsey@uk.ibm.com>
5: --FILE--
6: <?php
7:
8: // create a file
9: $filename = __FILE__ . ".tmp";
10: $fd = fopen($filename, "w+");
11:
12: // populate the file with lines of data
13: define("LINE_OF_DATA", "12345678\n");
14: for ($i = 0; $i < 1000; $i++) {
15: fwrite($fd, LINE_OF_DATA);
16: }
17: fclose($fd);
18:
19: /* Setup socket server */
20: $server = stream_socket_server('tcp://127.0.0.1:31337');
21:
22: /* Connect to it */
23: $client = fsockopen('tcp://127.0.0.1:31337');
24:
25: if (!$client) {
26: die("Unable to create socket");
27: }
28:
29: /* Accept that connection */
30: $socket = stream_socket_accept($server);
31:
32: echo "Write data from the file:\n";
33: $data = file_get_contents($filename);
34: unlink($filename);
35:
36: var_dump(fwrite($socket, $data));
37: fclose($socket);
38:
39: echo "\nRead lines from the client\n";
40: while ($line = fgets($client,256)) {
41: if (strcmp($line, LINE_OF_DATA) != 0) {
42: echo "Error - $line does not match " . LINE_OF_DATA;
43: break;
44: }
45: }
46:
47: echo "\nClose the server side socket and read the remaining data from the client\n";
48: fclose($server);
49: while(!feof($client)) {
50: fread($client, 1);
51: }
52:
53: echo "done\n";
54:
55: ?>
56: --EXPECT--
57: Write data from the file:
58: int(9000)
59:
60: Read lines from the client
61:
62: Close the server side socket and read the remaining data from the client
63: done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>