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  ["timed_out"]=>
47  bool(false)
48  ["blocked"]=>
49  bool(true)
50  ["eof"]=>
51  bool(false)
52  ["wrapper_type"]=>
53  string(9) "plainfile"
54  ["stream_type"]=>
55  string(5) "STDIO"
56  ["mode"]=>
57  string(2) "w+"
58  ["unread_bytes"]=>
59  int(0)
60  ["seekable"]=>
61  bool(true)
62  ["uri"]=>
63  string(%i) "%s.tmp"
64}
65
66
67Read a line of the file, causing data to be buffered:
68string(15) "a line of data
69"
70array(9) {
71  ["timed_out"]=>
72  bool(false)
73  ["blocked"]=>
74  bool(true)
75  ["eof"]=>
76  bool(false)
77  ["wrapper_type"]=>
78  string(9) "plainfile"
79  ["stream_type"]=>
80  string(5) "STDIO"
81  ["mode"]=>
82  string(2) "w+"
83  ["unread_bytes"]=>
84  int(285)
85  ["seekable"]=>
86  bool(true)
87  ["uri"]=>
88  string(%i) "%s.tmp"
89}
90
91
92Read 20 bytes from the file:
93array(9) {
94  ["timed_out"]=>
95  bool(false)
96  ["blocked"]=>
97  bool(true)
98  ["eof"]=>
99  bool(false)
100  ["wrapper_type"]=>
101  string(9) "plainfile"
102  ["stream_type"]=>
103  string(5) "STDIO"
104  ["mode"]=>
105  string(2) "w+"
106  ["unread_bytes"]=>
107  int(265)
108  ["seekable"]=>
109  bool(true)
110  ["uri"]=>
111  string(%i) "%s.tmp"
112}
113
114
115Read entire file:
116array(9) {
117  ["timed_out"]=>
118  bool(false)
119  ["blocked"]=>
120  bool(true)
121  ["eof"]=>
122  bool(true)
123  ["wrapper_type"]=>
124  string(9) "plainfile"
125  ["stream_type"]=>
126  string(5) "STDIO"
127  ["mode"]=>
128  string(2) "w+"
129  ["unread_bytes"]=>
130  int(0)
131  ["seekable"]=>
132  bool(true)
133  ["uri"]=>
134  string(%i) "%s.tmp"
135}
136