1--TEST-- 2Testing stream_get_meta_data() "eof" field on a udp socket 3--FILE-- 4<?php 5 6/* Setup socket server */ 7$server = stream_socket_server('tcp://127.0.0.1:31337'); 8 9/* Connect to it */ 10$client = fsockopen('tcp://127.0.0.1:31337'); 11if (!$client) { 12 die("Unable to create socket"); 13} 14 15/* Accept that connection */ 16$socket = stream_socket_accept($server); 17 18echo "Write some data:\n"; 19fwrite($socket, "abcdefg\n1234567\nxyzxyz\n"); 20var_dump(stream_get_meta_data($client)); 21 22echo "\n\nRead a line from the client:\n"; 23fgets($client); 24var_dump(stream_get_meta_data($client)); 25 26echo "\n\nClose the server side socket and read the remaining data from the client:\n"; 27fclose($socket); 28fclose($server); 29while(!feof($client)) { 30 fread($client, 1); 31} 32var_dump(stream_get_meta_data($client)); 33 34fclose($client); 35 36?> 37--EXPECTF-- 38Write some data: 39array(7) { 40 ["stream_type"]=> 41 string(%d) "tcp_socke%s" 42 ["mode"]=> 43 string(2) "r+" 44 ["unread_bytes"]=> 45 int(%i) 46 ["seekable"]=> 47 bool(false) 48 ["timed_out"]=> 49 bool(false) 50 ["blocked"]=> 51 bool(true) 52 ["eof"]=> 53 bool(false) 54} 55 56 57Read a line from the client: 58array(7) { 59 ["stream_type"]=> 60 string(%d) "tcp_socke%s" 61 ["mode"]=> 62 string(2) "r+" 63 ["unread_bytes"]=> 64 int(%i) 65 ["seekable"]=> 66 bool(false) 67 ["timed_out"]=> 68 bool(false) 69 ["blocked"]=> 70 bool(true) 71 ["eof"]=> 72 bool(false) 73} 74 75 76Close the server side socket and read the remaining data from the client: 77array(7) { 78 ["stream_type"]=> 79 string(%d) "tcp_socke%s" 80 ["mode"]=> 81 string(2) "r+" 82 ["unread_bytes"]=> 83 int(%i) 84 ["seekable"]=> 85 bool(false) 86 ["timed_out"]=> 87 bool(false) 88 ["blocked"]=> 89 bool(true) 90 ["eof"]=> 91 bool(true) 92} 93