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 linux");
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 of 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 with 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
48    // opening the file in different modes
49    $file_handle = fopen($file_name, $mode);
50    if($file_handle == false)
51      exit("Error:failed to open file $file_name");
52
53    // writing data to the file
54    var_dump( fill_file($file_handle, $type, 50) );
55    var_dump( fflush($file_handle) );
56    fclose($file_handle);
57
58    // reading the contents of the file after flushing
59     var_dump( readfile($file_name) );
60     unlink($file_name);
61  }
62  $count++;
63}
64
65echo "\n*** Done ***";
66?>
67--EXPECTF--
68*** Testing fflush(): with various types of files ***
69-- Iteration 1 with file containing empty Data--
70-- File opened in w mode --
71bool(true)
72bool(true)
73int(0)
74-- File opened in wb mode --
75bool(true)
76bool(true)
77int(0)
78-- File opened in wt mode --
79bool(true)
80bool(true)
81int(0)
82-- File opened in w+ mode --
83bool(true)
84bool(true)
85int(0)
86-- File opened in w+b mode --
87bool(true)
88bool(true)
89int(0)
90-- File opened in w+t mode --
91bool(true)
92bool(true)
93int(0)
94-- File opened in a mode --
95bool(true)
96bool(true)
97int(0)
98-- File opened in ab mode --
99bool(true)
100bool(true)
101int(0)
102-- File opened in at mode --
103bool(true)
104bool(true)
105int(0)
106-- File opened in a+ mode --
107bool(true)
108bool(true)
109int(0)
110-- File opened in a+b mode --
111bool(true)
112bool(true)
113int(0)
114-- File opened in a+t mode --
115bool(true)
116bool(true)
117int(0)
118-- File opened in x mode --
119bool(true)
120bool(true)
121int(0)
122-- File opened in xb mode --
123bool(true)
124bool(true)
125int(0)
126-- File opened in xt mode --
127bool(true)
128bool(true)
129int(0)
130-- File opened in x+ mode --
131bool(true)
132bool(true)
133int(0)
134-- File opened in x+b mode --
135bool(true)
136bool(true)
137int(0)
138-- File opened in x+t mode --
139bool(true)
140bool(true)
141int(0)
142-- Iteration 2 with file containing numeric Data--
143-- File opened in w mode --
144bool(true)
145bool(true)
14622222222222222222222222222222222222222222222222222int(50)
147-- File opened in wb mode --
148bool(true)
149bool(true)
15022222222222222222222222222222222222222222222222222int(50)
151-- File opened in wt mode --
152bool(true)
153bool(true)
15422222222222222222222222222222222222222222222222222int(50)
155-- File opened in w+ mode --
156bool(true)
157bool(true)
15822222222222222222222222222222222222222222222222222int(50)
159-- File opened in w+b mode --
160bool(true)
161bool(true)
16222222222222222222222222222222222222222222222222222int(50)
163-- File opened in w+t mode --
164bool(true)
165bool(true)
16622222222222222222222222222222222222222222222222222int(50)
167-- File opened in a mode --
168bool(true)
169bool(true)
170222222222222222222222222222222222222222222222222222222222222int(60)
171-- File opened in ab mode --
172bool(true)
173bool(true)
174222222222222222222222222222222222222222222222222222222222222int(60)
175-- File opened in at mode --
176bool(true)
177bool(true)
178222222222222222222222222222222222222222222222222222222222222int(60)
179-- File opened in a+ mode --
180bool(true)
181bool(true)
182222222222222222222222222222222222222222222222222222222222222int(60)
183-- File opened in a+b mode --
184bool(true)
185bool(true)
186222222222222222222222222222222222222222222222222222222222222int(60)
187-- File opened in a+t mode --
188bool(true)
189bool(true)
190222222222222222222222222222222222222222222222222222222222222int(60)
191-- File opened in x mode --
192bool(true)
193bool(true)
19422222222222222222222222222222222222222222222222222int(50)
195-- File opened in xb mode --
196bool(true)
197bool(true)
19822222222222222222222222222222222222222222222222222int(50)
199-- File opened in xt mode --
200bool(true)
201bool(true)
20222222222222222222222222222222222222222222222222222int(50)
203-- File opened in x+ mode --
204bool(true)
205bool(true)
20622222222222222222222222222222222222222222222222222int(50)
207-- File opened in x+b mode --
208bool(true)
209bool(true)
21022222222222222222222222222222222222222222222222222int(50)
211-- File opened in x+t mode --
212bool(true)
213bool(true)
21422222222222222222222222222222222222222222222222222int(50)
215-- Iteration 3 with file containing text Data--
216-- File opened in w mode --
217bool(true)
218bool(true)
219text text text text text text text text text text int(50)
220-- File opened in wb mode --
221bool(true)
222bool(true)
223text text text text text text text text text text int(50)
224-- File opened in wt mode --
225bool(true)
226bool(true)
227text text text text text text text text text text int(50)
228-- File opened in w+ mode --
229bool(true)
230bool(true)
231text text text text text text text text text text int(50)
232-- File opened in w+b mode --
233bool(true)
234bool(true)
235text text text text text text text text text text int(50)
236-- File opened in w+t mode --
237bool(true)
238bool(true)
239text text text text text text text text text text int(50)
240-- File opened in a mode --
241bool(true)
242bool(true)
243text text text text text text text text text text text text int(60)
244-- File opened in ab mode --
245bool(true)
246bool(true)
247text text text text text text text text text text text text int(60)
248-- File opened in at mode --
249bool(true)
250bool(true)
251text text text text text text text text text text text text int(60)
252-- File opened in a+ mode --
253bool(true)
254bool(true)
255text text text text text text text text text text text text int(60)
256-- File opened in a+b mode --
257bool(true)
258bool(true)
259text text text text text text text text text text text text int(60)
260-- File opened in a+t mode --
261bool(true)
262bool(true)
263text text text text text text text text text text text text int(60)
264-- File opened in x mode --
265bool(true)
266bool(true)
267text text text text text text text text text text int(50)
268-- File opened in xb mode --
269bool(true)
270bool(true)
271text text text text text text text text text text int(50)
272-- File opened in xt mode --
273bool(true)
274bool(true)
275text text text text text text text text text text int(50)
276-- File opened in x+ mode --
277bool(true)
278bool(true)
279text text text text text text text text text text int(50)
280-- File opened in x+b mode --
281bool(true)
282bool(true)
283text text text text text text text text text text int(50)
284-- File opened in x+t mode --
285bool(true)
286bool(true)
287text text text text text text text text text text int(50)
288-- Iteration 4 with file containing text_with_new_line Data--
289-- File opened in w mode --
290bool(true)
291bool(true)
292line
293line of text
294line
295line of text
296line
297line of tint(50)
298-- File opened in wb mode --
299bool(true)
300bool(true)
301line
302line of text
303line
304line of text
305line
306line of tint(50)
307-- File opened in wt mode --
308bool(true)
309bool(true)
310line
311line of text
312line
313line of text
314line
315line of tint(50)
316-- File opened in w+ mode --
317bool(true)
318bool(true)
319line
320line of text
321line
322line of text
323line
324line of tint(50)
325-- File opened in w+b mode --
326bool(true)
327bool(true)
328line
329line of text
330line
331line of text
332line
333line of tint(50)
334-- File opened in w+t mode --
335bool(true)
336bool(true)
337line
338line of text
339line
340line of text
341line
342line of tint(50)
343-- File opened in a mode --
344bool(true)
345bool(true)
346line
347line line
348line of text
349line
350line of text
351line
352line of tint(60)
353-- File opened in ab mode --
354bool(true)
355bool(true)
356line
357line line
358line of text
359line
360line of text
361line
362line of tint(60)
363-- File opened in at mode --
364bool(true)
365bool(true)
366line
367line line
368line of text
369line
370line of text
371line
372line of tint(60)
373-- File opened in a+ mode --
374bool(true)
375bool(true)
376line
377line line
378line of text
379line
380line of text
381line
382line of tint(60)
383-- File opened in a+b mode --
384bool(true)
385bool(true)
386line
387line line
388line of text
389line
390line of text
391line
392line of tint(60)
393-- File opened in a+t mode --
394bool(true)
395bool(true)
396line
397line line
398line of text
399line
400line of text
401line
402line of tint(60)
403-- File opened in x mode --
404bool(true)
405bool(true)
406line
407line of text
408line
409line of text
410line
411line of tint(50)
412-- File opened in xb mode --
413bool(true)
414bool(true)
415line
416line of text
417line
418line of text
419line
420line of tint(50)
421-- File opened in xt mode --
422bool(true)
423bool(true)
424line
425line of text
426line
427line of text
428line
429line of tint(50)
430-- File opened in x+ mode --
431bool(true)
432bool(true)
433line
434line of text
435line
436line of text
437line
438line of tint(50)
439-- File opened in x+b mode --
440bool(true)
441bool(true)
442line
443line of text
444line
445line of text
446line
447line of tint(50)
448-- File opened in x+t mode --
449bool(true)
450bool(true)
451line
452line of text
453line
454line of text
455line
456line of tint(50)
457-- Iteration 5 with file containing alphanumeric Data--
458-- File opened in w mode --
459bool(true)
460bool(true)
461ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
462-- File opened in wb mode --
463bool(true)
464bool(true)
465ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
466-- File opened in wt mode --
467bool(true)
468bool(true)
469ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
470-- File opened in w+ mode --
471bool(true)
472bool(true)
473ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
474-- File opened in w+b mode --
475bool(true)
476bool(true)
477ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
478-- File opened in w+t mode --
479bool(true)
480bool(true)
481ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
482-- File opened in a mode --
483bool(true)
484bool(true)
485ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
486-- File opened in ab mode --
487bool(true)
488bool(true)
489ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
490-- File opened in at mode --
491bool(true)
492bool(true)
493ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
494-- File opened in a+ mode --
495bool(true)
496bool(true)
497ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
498-- File opened in a+b mode --
499bool(true)
500bool(true)
501ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
502-- File opened in a+t mode --
503bool(true)
504bool(true)
505ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
506-- File opened in x mode --
507bool(true)
508bool(true)
509ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
510-- File opened in xb mode --
511bool(true)
512bool(true)
513ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
514-- File opened in xt mode --
515bool(true)
516bool(true)
517ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
518-- File opened in x+ mode --
519bool(true)
520bool(true)
521ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
522-- File opened in x+b mode --
523bool(true)
524bool(true)
525ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
526-- File opened in x+t mode --
527bool(true)
528bool(true)
529ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
530
531*** Done ***
532
533