1--TEST-- 2Testing stream_get_meta_data() "timed_out" field on a udp socket 3--FILE-- 4<?php 5 6/* Setup socket server */ 7$server = stream_socket_server('tcp://127.0.0.1:31332'); 8 9/* Connect to it */ 10$client = fsockopen('tcp://127.0.0.1:31332'); 11if (!$client) { 12 die("Unable to create socket"); 13} 14 15/* Accept that connection */ 16$socket = stream_socket_accept($server); 17 18var_dump(stream_get_meta_data($client)); 19 20echo "\n\nSet a timeout on the client and attempt a read:\n"; 21socket_set_timeout($client, 0, 1000); 22fread($client, 1); 23var_dump(stream_get_meta_data($client)); 24 25echo "\n\nWrite some data from the server:\n"; 26fwrite($socket, "12345"); 27var_dump(stream_get_meta_data($client)); 28 29echo "\n\nRead some data from the client:\n"; 30fread($client, 5); 31var_dump(stream_get_meta_data($client)); 32 33fclose($client); 34fclose($socket); 35fclose($server); 36 37?> 38--EXPECTF-- 39array(8) { 40 ["timed_out"]=> 41 bool(false) 42 ["blocked"]=> 43 bool(true) 44 ["eof"]=> 45 bool(false) 46 ["stream_type"]=> 47 string(%d) "tcp_socke%s" 48 ["mode"]=> 49 string(2) "r+" 50 ["unread_bytes"]=> 51 int(0) 52 ["seekable"]=> 53 bool(false) 54 ["uri"]=> 55 string(21) "tcp://127.0.0.1:31332" 56} 57 58 59Set a timeout on the client and attempt a read: 60array(8) { 61 ["timed_out"]=> 62 bool(true) 63 ["blocked"]=> 64 bool(true) 65 ["eof"]=> 66 bool(false) 67 ["stream_type"]=> 68 string(%d) "tcp_socke%s" 69 ["mode"]=> 70 string(2) "r+" 71 ["unread_bytes"]=> 72 int(0) 73 ["seekable"]=> 74 bool(false) 75 ["uri"]=> 76 string(21) "tcp://127.0.0.1:31332" 77} 78 79 80Write some data from the server: 81array(8) { 82 ["timed_out"]=> 83 bool(true) 84 ["blocked"]=> 85 bool(true) 86 ["eof"]=> 87 bool(false) 88 ["stream_type"]=> 89 string(%d) "tcp_socke%s" 90 ["mode"]=> 91 string(2) "r+" 92 ["unread_bytes"]=> 93 int(0) 94 ["seekable"]=> 95 bool(false) 96 ["uri"]=> 97 string(21) "tcp://127.0.0.1:31332" 98} 99 100 101Read some data from the client: 102array(8) { 103 ["timed_out"]=> 104 bool(false) 105 ["blocked"]=> 106 bool(true) 107 ["eof"]=> 108 bool(false) 109 ["stream_type"]=> 110 string(%d) "tcp_socke%s" 111 ["mode"]=> 112 string(2) "r+" 113 ["unread_bytes"]=> 114 int(0) 115 ["seekable"]=> 116 bool(false) 117 ["uri"]=> 118 string(21) "tcp://127.0.0.1:31332" 119} 120