1--TEST-- 2Testing stream_get_meta_data() "unread_bytes" field 3--FILE-- 4<?php 5 6$filename = __FILE__ . '.tmp'; 7 8$fp = fopen($filename, "w+"); 9 10echo "Write some data to the file:\n"; 11$i = 0; 12while ($i++ < 20) { 13 fwrite($fp, "a line of data\n"); 14} 15 16var_dump(stream_get_meta_data($fp)); 17 18//seek to start of file 19rewind($fp); 20 21echo "\n\nRead a line of the file, causing data to be buffered:\n"; 22var_dump(fgets($fp)); 23 24var_dump(stream_get_meta_data($fp)); 25 26echo "\n\nRead 20 bytes from the file:\n"; 27fread($fp, 20); 28 29var_dump(stream_get_meta_data($fp)); 30 31echo "\n\nRead entire file:\n"; 32while(!feof($fp)) { 33 fread($fp, 1); 34} 35 36var_dump(stream_get_meta_data($fp)); 37 38fclose($fp); 39 40unlink($filename); 41 42?> 43--EXPECTF-- 44Write some data to the file: 45array(9) { 46 ["wrapper_type"]=> 47 string(9) "plainfile" 48 ["stream_type"]=> 49 string(5) "STDIO" 50 ["mode"]=> 51 string(2) "w+" 52 ["unread_bytes"]=> 53 int(0) 54 ["seekable"]=> 55 bool(true) 56 ["uri"]=> 57 string(%i) "%s.tmp" 58 ["timed_out"]=> 59 bool(false) 60 ["blocked"]=> 61 bool(true) 62 ["eof"]=> 63 bool(false) 64} 65 66 67Read a line of the file, causing data to be buffered: 68string(15) "a line of data 69" 70array(9) { 71 ["wrapper_type"]=> 72 string(9) "plainfile" 73 ["stream_type"]=> 74 string(5) "STDIO" 75 ["mode"]=> 76 string(2) "w+" 77 ["unread_bytes"]=> 78 int(285) 79 ["seekable"]=> 80 bool(true) 81 ["uri"]=> 82 string(%i) "%s.tmp" 83 ["timed_out"]=> 84 bool(false) 85 ["blocked"]=> 86 bool(true) 87 ["eof"]=> 88 bool(false) 89} 90 91 92Read 20 bytes from the file: 93array(9) { 94 ["wrapper_type"]=> 95 string(9) "plainfile" 96 ["stream_type"]=> 97 string(5) "STDIO" 98 ["mode"]=> 99 string(2) "w+" 100 ["unread_bytes"]=> 101 int(265) 102 ["seekable"]=> 103 bool(true) 104 ["uri"]=> 105 string(%i) "%s.tmp" 106 ["timed_out"]=> 107 bool(false) 108 ["blocked"]=> 109 bool(true) 110 ["eof"]=> 111 bool(false) 112} 113 114 115Read entire file: 116array(9) { 117 ["wrapper_type"]=> 118 string(9) "plainfile" 119 ["stream_type"]=> 120 string(5) "STDIO" 121 ["mode"]=> 122 string(2) "w+" 123 ["unread_bytes"]=> 124 int(0) 125 ["seekable"]=> 126 bool(true) 127 ["uri"]=> 128 string(%i) "%s.tmp" 129 ["timed_out"]=> 130 bool(false) 131 ["blocked"]=> 132 bool(true) 133 ["eof"]=> 134 bool(true) 135} 136