1--TEST--
2Test fflush() function: usage variations - files in different modes
3--SKIPIF--
4<?php
5if( substr(PHP_OS, 0, 3) != "WIN" )
6  die("skip.. only for Windows");
7?>
8
9--FILE--
10<?php
11/*  Prototype: bool fflush ( resource $handle );
12    Description: Flushes the output to a file
13*/
14
15/* test fflush() with handle to the files opened in different modes */
16
17$file_path = dirname(__FILE__);
18require $file_path.'/file.inc';
19
20echo "*** Testing fflush(): with various types of files ***\n";
21$file_types = array("empty", "numeric", "text", "text_with_new_line", "alphanumeric");
22$file_modes = array("w", "wb", "wt", "w+", "w+b", "w+t",
23                    "a", "ab", "at", "a+","a+b", "a+t",
24                    "x", "xb", "xt", "x+", "x+b", "x+t");
25
26$file_name = "$file_path/fflush_variation1.tmp";
27
28$count = 1;
29
30foreach( $file_types as $type ) {
31  echo "-- Iteration $count with file containing $type Data--\n";
32  foreach( $file_modes as $mode ) {
33    echo "-- File opened in $mode mode --\n";
34
35    // creating the file except for x mode
36    if( substr($mode, 0, 1) != "x" ) {
37      $file_handle = fopen($file_name, "w");
38      if($file_handle == false)
39        exit("Error:failed to open file $file_name");
40
41      // filling the file some data if mode is append mode
42      if( substr($mode, 0, 1) == "a")
43        fill_file($file_handle, $type, 10);
44      fclose($file_handle);
45    }
46
47    // opening the file in different modes
48    $file_handle = fopen($file_name, $mode);
49    if($file_handle == false)
50      exit("Error:failed to open file $file_name");
51
52    // writing data to the file
53    var_dump( fill_file($file_handle, $type, 50) );
54    var_dump( fflush($file_handle) );
55    fclose($file_handle);
56
57    // reading the contents of the file after flushing
58     var_dump( readfile($file_name) );
59     unlink($file_name);
60  }
61  $count++;
62}
63
64echo "\n*** Done ***";
65?>
66--EXPECTF--
67*** Testing fflush(): with various types of files ***
68-- Iteration 1 with file containing empty Data--
69-- File opened in w mode --
70bool(true)
71bool(true)
72int(0)
73-- File opened in wb mode --
74bool(true)
75bool(true)
76int(0)
77-- File opened in wt mode --
78bool(true)
79bool(true)
80int(0)
81-- File opened in w+ mode --
82bool(true)
83bool(true)
84int(0)
85-- File opened in w+b mode --
86bool(true)
87bool(true)
88int(0)
89-- File opened in w+t mode --
90bool(true)
91bool(true)
92int(0)
93-- File opened in a mode --
94bool(true)
95bool(true)
96int(0)
97-- File opened in ab mode --
98bool(true)
99bool(true)
100int(0)
101-- File opened in at mode --
102bool(true)
103bool(true)
104int(0)
105-- File opened in a+ mode --
106bool(true)
107bool(true)
108int(0)
109-- File opened in a+b mode --
110bool(true)
111bool(true)
112int(0)
113-- File opened in a+t mode --
114bool(true)
115bool(true)
116int(0)
117-- File opened in x mode --
118bool(true)
119bool(true)
120int(0)
121-- File opened in xb mode --
122bool(true)
123bool(true)
124int(0)
125-- File opened in xt mode --
126bool(true)
127bool(true)
128int(0)
129-- File opened in x+ mode --
130bool(true)
131bool(true)
132int(0)
133-- File opened in x+b mode --
134bool(true)
135bool(true)
136int(0)
137-- File opened in x+t mode --
138bool(true)
139bool(true)
140int(0)
141-- Iteration 2 with file containing numeric Data--
142-- File opened in w mode --
143bool(true)
144bool(true)
14522222222222222222222222222222222222222222222222222int(50)
146-- File opened in wb mode --
147bool(true)
148bool(true)
14922222222222222222222222222222222222222222222222222int(50)
150-- File opened in wt mode --
151bool(true)
152bool(true)
15322222222222222222222222222222222222222222222222222int(50)
154-- File opened in w+ mode --
155bool(true)
156bool(true)
15722222222222222222222222222222222222222222222222222int(50)
158-- File opened in w+b mode --
159bool(true)
160bool(true)
16122222222222222222222222222222222222222222222222222int(50)
162-- File opened in w+t mode --
163bool(true)
164bool(true)
16522222222222222222222222222222222222222222222222222int(50)
166-- File opened in a mode --
167bool(true)
168bool(true)
169222222222222222222222222222222222222222222222222222222222222int(60)
170-- File opened in ab mode --
171bool(true)
172bool(true)
173222222222222222222222222222222222222222222222222222222222222int(60)
174-- File opened in at mode --
175bool(true)
176bool(true)
177222222222222222222222222222222222222222222222222222222222222int(60)
178-- File opened in a+ mode --
179bool(true)
180bool(true)
181222222222222222222222222222222222222222222222222222222222222int(60)
182-- File opened in a+b mode --
183bool(true)
184bool(true)
185222222222222222222222222222222222222222222222222222222222222int(60)
186-- File opened in a+t mode --
187bool(true)
188bool(true)
189222222222222222222222222222222222222222222222222222222222222int(60)
190-- File opened in x mode --
191bool(true)
192bool(true)
19322222222222222222222222222222222222222222222222222int(50)
194-- File opened in xb mode --
195bool(true)
196bool(true)
19722222222222222222222222222222222222222222222222222int(50)
198-- File opened in xt mode --
199bool(true)
200bool(true)
20122222222222222222222222222222222222222222222222222int(50)
202-- File opened in x+ mode --
203bool(true)
204bool(true)
20522222222222222222222222222222222222222222222222222int(50)
206-- File opened in x+b mode --
207bool(true)
208bool(true)
20922222222222222222222222222222222222222222222222222int(50)
210-- File opened in x+t mode --
211bool(true)
212bool(true)
21322222222222222222222222222222222222222222222222222int(50)
214-- Iteration 3 with file containing text Data--
215-- File opened in w mode --
216bool(true)
217bool(true)
218text text text text text text text text text text int(50)
219-- File opened in wb mode --
220bool(true)
221bool(true)
222text text text text text text text text text text int(50)
223-- File opened in wt mode --
224bool(true)
225bool(true)
226text text text text text text text text text text int(50)
227-- File opened in w+ mode --
228bool(true)
229bool(true)
230text text text text text text text text text text int(50)
231-- File opened in w+b mode --
232bool(true)
233bool(true)
234text text text text text text text text text text int(50)
235-- File opened in w+t mode --
236bool(true)
237bool(true)
238text text text text text text text text text text int(50)
239-- File opened in a mode --
240bool(true)
241bool(true)
242text text text text text text text text text text text text int(60)
243-- File opened in ab mode --
244bool(true)
245bool(true)
246text text text text text text text text text text text text int(60)
247-- File opened in at mode --
248bool(true)
249bool(true)
250text text text text text text text text text text text text int(60)
251-- File opened in a+ mode --
252bool(true)
253bool(true)
254text text text text text text text text text text text text int(60)
255-- File opened in a+b mode --
256bool(true)
257bool(true)
258text text text text text text text text text text text text int(60)
259-- File opened in a+t mode --
260bool(true)
261bool(true)
262text text text text text text text text text text text text int(60)
263-- File opened in x mode --
264bool(true)
265bool(true)
266text text text text text text text text text text int(50)
267-- File opened in xb mode --
268bool(true)
269bool(true)
270text text text text text text text text text text int(50)
271-- File opened in xt mode --
272bool(true)
273bool(true)
274text text text text text text text text text text int(50)
275-- File opened in x+ mode --
276bool(true)
277bool(true)
278text text text text text text text text text text int(50)
279-- File opened in x+b mode --
280bool(true)
281bool(true)
282text text text text text text text text text text int(50)
283-- File opened in x+t mode --
284bool(true)
285bool(true)
286text text text text text text text text text text int(50)
287-- Iteration 4 with file containing text_with_new_line Data--
288-- File opened in w mode --
289bool(true)
290bool(true)
291line
292line of text
293line
294line of text
295line
296line of tint(50)
297-- File opened in wb mode --
298bool(true)
299bool(true)
300line
301line of text
302line
303line of text
304line
305line of tint(50)
306-- File opened in wt mode --
307bool(true)
308bool(true)
309line
310line of text
311line
312line of text
313line
314line of tint(55)
315-- File opened in w+ mode --
316bool(true)
317bool(true)
318line
319line of text
320line
321line of text
322line
323line of tint(50)
324-- File opened in w+b mode --
325bool(true)
326bool(true)
327line
328line of text
329line
330line of text
331line
332line of tint(50)
333-- File opened in w+t mode --
334bool(true)
335bool(true)
336line
337line of text
338line
339line of text
340line
341line of tint(55)
342-- File opened in a mode --
343bool(true)
344bool(true)
345line
346line line
347line of text
348line
349line of text
350line
351line of tint(60)
352-- File opened in ab mode --
353bool(true)
354bool(true)
355line
356line line
357line of text
358line
359line of text
360line
361line of tint(60)
362-- File opened in at mode --
363bool(true)
364bool(true)
365line
366line line
367line of text
368line
369line of text
370line
371line of tint(65)
372-- File opened in a+ mode --
373bool(true)
374bool(true)
375line
376line line
377line of text
378line
379line of text
380line
381line of tint(60)
382-- File opened in a+b mode --
383bool(true)
384bool(true)
385line
386line line
387line of text
388line
389line of text
390line
391line of tint(60)
392-- File opened in a+t mode --
393bool(true)
394bool(true)
395line
396line line
397line of text
398line
399line of text
400line
401line of tint(65)
402-- File opened in x mode --
403bool(true)
404bool(true)
405line
406line of text
407line
408line of text
409line
410line of tint(50)
411-- File opened in xb mode --
412bool(true)
413bool(true)
414line
415line of text
416line
417line of text
418line
419line of tint(50)
420-- File opened in xt mode --
421bool(true)
422bool(true)
423line
424line of text
425line
426line of text
427line
428line of tint(55)
429-- File opened in x+ mode --
430bool(true)
431bool(true)
432line
433line of text
434line
435line of text
436line
437line of tint(50)
438-- File opened in x+b mode --
439bool(true)
440bool(true)
441line
442line of text
443line
444line of text
445line
446line of tint(50)
447-- File opened in x+t mode --
448bool(true)
449bool(true)
450line
451line of text
452line
453line of text
454line
455line of tint(55)
456-- Iteration 5 with file containing alphanumeric Data--
457-- File opened in w mode --
458bool(true)
459bool(true)
460ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
461-- File opened in wb mode --
462bool(true)
463bool(true)
464ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
465-- File opened in wt mode --
466bool(true)
467bool(true)
468ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
469-- File opened in w+ mode --
470bool(true)
471bool(true)
472ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
473-- File opened in w+b mode --
474bool(true)
475bool(true)
476ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
477-- File opened in w+t mode --
478bool(true)
479bool(true)
480ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
481-- File opened in a mode --
482bool(true)
483bool(true)
484ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
485-- File opened in ab mode --
486bool(true)
487bool(true)
488ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
489-- File opened in at mode --
490bool(true)
491bool(true)
492ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
493-- File opened in a+ mode --
494bool(true)
495bool(true)
496ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
497-- File opened in a+b mode --
498bool(true)
499bool(true)
500ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
501-- File opened in a+t mode --
502bool(true)
503bool(true)
504ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
505-- File opened in x mode --
506bool(true)
507bool(true)
508ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
509-- File opened in xb mode --
510bool(true)
511bool(true)
512ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
513-- File opened in xt mode --
514bool(true)
515bool(true)
516ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
517-- File opened in x+ mode --
518bool(true)
519bool(true)
520ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
521-- File opened in x+b mode --
522bool(true)
523bool(true)
524ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
525-- File opened in x+t mode --
526bool(true)
527bool(true)
528ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
529
530*** Done ***
531
532