1--TEST-- 2stream_socket_shutdown() test on IPv4 TCP Loopback 3--SKIPIF-- 4<?php 5 function_exists('stream_socket_shutdown') or die('skip stream_socket_shutdown() is not supported.'); 6?> 7--FILE-- 8<?php 9 /* Setup socket server */ 10 $server = stream_socket_server('tcp://127.0.0.1:31337'); 11 if (!$server) { 12 die('Unable to create AF_INET socket [server]'); 13 } 14 15 /* Connect and send request 1 */ 16 $client1 = stream_socket_client('tcp://127.0.0.1:31337'); 17 if (!$client1) { 18 die('Unable to create AF_INET socket [client]'); 19 } 20 @fwrite($client1, "Client 1\n"); 21 stream_socket_shutdown($client1, STREAM_SHUT_WR); 22 @fwrite($client1, "Error 1\n"); 23 24 /* Connect and send request 2 */ 25 $client2 = stream_socket_client('tcp://127.0.0.1:31337'); 26 if (!$client2) { 27 die('Unable to create AF_INET socket [client]'); 28 } 29 @fwrite($client2, "Client 2\n"); 30 stream_socket_shutdown($client2, STREAM_SHUT_WR); 31 @fwrite($client2, "Error 2\n"); 32 33 /* Accept connection 1 */ 34 $socket = stream_socket_accept($server); 35 if (!$socket) { 36 die('Unable to accept connection'); 37 } 38 @fwrite($socket, fgets($socket)); 39 @fwrite($socket, fgets($socket)); 40 fclose($socket); 41 42 /* Read Response 1 */ 43 echo fgets($client1); 44 echo fgets($client1); 45 46 /* Accept connection 2 */ 47 $socket = stream_socket_accept($server); 48 if (!$socket) { 49 die('Unable to accept connection'); 50 } 51 @fwrite($socket, fgets($socket)); 52 @fwrite($socket, fgets($socket)); 53 fclose($socket); 54 55 /* Read Response 2 */ 56 echo fgets($client2); 57 echo fgets($client2); 58 59 fclose($client1); 60 fclose($client2); 61 fclose($server); 62?> 63--EXPECT-- 64Client 1 65Client 2 66