1--TEST-- 2Streams Based IPv6 TCP Loopback test 3--SKIPIF-- 4<?php 5 /* If IPv6 is supported on the platform this will error out with code 111 - Connection refused (or code 10049 on Windows). 6 If IPv6 is NOT supported, $errno will be set to something else (indicating parse/getaddrinfo error) 7 Note: Might be a good idea to export an IPv6 support indicator (such as AF_INET6 exported by ext/sockets) */ 8 @stream_socket_client('tcp://[::1]:0', $errno); 9 if ((PHP_OS_FAMILY === 'Windows' && $errno !== 10049) || (PHP_OS_FAMILY !== 'Windows' && $errno !== 111)) { 10 die('skip IPv6 is not supported.'); 11 } 12?> 13--FILE-- 14<?php 15 16 for ($i=0; $i<100; $i++) { 17 $port = rand(10000, 65000); 18 /* Setup socket server */ 19 $server = @stream_socket_server("tcp://[::1]:$port"); 20 if ($server) { 21 break; 22 } 23 } 24 25 if (!$server) { 26 die('Unable to create AF_INET6 socket [server]'); 27 } 28 29 /* Connect to it */ 30 $client = stream_socket_client("tcp://[::1]:$port"); 31 if (!$client) { 32 die('Unable to create AF_INET6 socket [client]'); 33 } 34 35 /* Accept that connection */ 36 $socket = stream_socket_accept($server); 37 if (!$socket) { 38 die('Unable to accept connection'); 39 } 40 41 fwrite($client, "ABCdef123\n"); 42 43 $data = fread($socket, 10); 44 var_dump($data); 45 46 fclose($client); 47 fclose($socket); 48 fclose($server); 49?> 50--EXPECT-- 51string(10) "ABCdef123 52" 53