1--TEST-- 2socket_export_stream: effects of closing 3--SKIPIF-- 4<?php 5if (!extension_loaded('sockets')) { 6 die('SKIP sockets extension not available.'); 7} 8if(substr(PHP_OS, 0, 3) == 'WIN' ) { 9 die("skip Not Valid for Windows"); 10} 11--FILE-- 12<?php 13 14function test($stream, $sock) { 15 if ($stream !== null) { 16 echo "stream_set_blocking "; 17 print_r(stream_set_blocking($stream, 0)); 18 echo "\n"; 19 } 20 if ($sock !== null) { 21 echo "socket_set_block "; 22 print_r(socket_set_block($sock)); 23 echo "\n"; 24 echo "socket_get_option "; 25 print_r(socket_get_option($sock, SOL_SOCKET, SO_TYPE)); 26 echo "\n"; 27 } 28 echo "\n"; 29} 30 31echo "normal\n"; 32$sock0 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); 33socket_bind($sock0, '0.0.0.0', 58380); 34$stream0 = socket_export_stream($sock0); 35test($stream0, $sock0); 36 37echo "\nunset stream\n"; 38$sock1 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); 39socket_bind($sock1, '0.0.0.0', 58381); 40$stream1 = socket_export_stream($sock1); 41unset($stream1); 42test(null, $sock1); 43 44echo "\nunset socket\n"; 45$sock2 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); 46socket_bind($sock2, '0.0.0.0', 58382); 47$stream2 = socket_export_stream($sock2); 48unset($sock2); 49test($stream2, null); 50 51echo "\nclose stream\n"; 52$sock3 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); 53socket_bind($sock3, '0.0.0.0', 58383); 54$stream3 = socket_export_stream($sock3); 55fclose($stream3); 56test($stream3, $sock3); 57 58echo "\nclose socket\n"; 59$sock4 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); 60socket_bind($sock4, '0.0.0.0', 58484); 61$stream4 = socket_export_stream($sock4); 62socket_close($sock4); 63test($stream4, $sock4); 64 65echo "Done.\n"; 66--EXPECTF-- 67normal 68stream_set_blocking 1 69socket_set_block 1 70socket_get_option 2 71 72 73unset stream 74socket_set_block 1 75socket_get_option 2 76 77 78unset socket 79stream_set_blocking 1 80 81 82close stream 83stream_set_blocking 84Warning: stream_set_blocking(): supplied resource is not a valid stream resource in %s on line %d 85 86socket_set_block 87Warning: socket_set_block(): unable to set blocking mode [%d]: %s in %s on line %d 88 89socket_get_option 90Warning: socket_get_option(): unable to retrieve socket option [%d]: %s in %s on line %d 91 92 93 94close socket 95stream_set_blocking 96Warning: stream_set_blocking(): supplied resource is not a valid stream resource in %s on line %d 97 98socket_set_block 99Warning: socket_set_block(): supplied resource is not a valid Socket resource in %s on line %d 100 101socket_get_option 102Warning: socket_get_option(): supplied resource is not a valid Socket resource in %s on line %d 103 104 105Done. 106