Return to fgets_socket_variation1.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / file |
1.1 misho 1: --TEST-- 2: fgets() with a socket stream 3: --CREDITS-- 4: Dave 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: 14: if (!$client) { 15: die("Unable to create socket"); 16: } 17: 18: /* Accept that connection */ 19: $socket = stream_socket_accept($server); 20: 21: echo "Write some data:\n"; 22: fwrite($socket, "line1\nline2\nline3\n"); 23: 24: 25: echo "\n\nRead a line from the client:\n"; 26: var_dump(fgets($client)); 27: 28: echo "\n\nRead another line from the client:\n"; 29: var_dump(fgets($client)); 30: 31: echo "\n\nClose the server side socket and read the remaining data from the client\n"; 32: fclose($socket); 33: fclose($server); 34: while(!feof($client)) { 35: fread($client, 1); 36: } 37: 38: echo "done\n"; 39: 40: ?> 41: --EXPECT-- 42: Write some data: 43: 44: 45: Read a line from the client: 46: string(6) "line1 47: " 48: 49: 50: Read another line from the client: 51: string(6) "line2 52: " 53: 54: 55: Close the server side socket and read the remaining data from the client 56: done