1--TEST--
2Test fflush() function: basic functionality
3--FILE--
4<?php
5/*  Prototype: bool fflush ( resource $handle );
6    Description: Flushes the output to a file
7*/
8
9echo "*** Testing fflush(): writing to a file and reading the contents ***\n";
10$data = <<<EOD
11first line of string
12second line of string
13third line of string
14EOD;
15
16$file_path = dirname(__FILE__);
17$filename = "$file_path/fflush_basic.tmp";
18
19// opening a file
20$file_handle = fopen($filename, "w");
21if($file_handle == false)
22  exit("Error:failed to open file $filename");
23
24if(substr(PHP_OS, 0, 3) == "WIN")  {
25	$data = str_replace("\r",'', $data);
26}
27
28// writing data to the file
29var_dump( fwrite($file_handle, $data) );
30var_dump( fflush($file_handle) );
31var_dump( readfile($filename) );
32
33echo "\n*** Testing fflush(): for return type ***\n";
34$return_value = fflush($file_handle);
35var_dump( is_bool($return_value) );
36fclose($file_handle);
37echo "\n*** Done ***";
38?>
39
40--CLEAN--
41<?php
42$file_path = dirname(__FILE__);
43$filename = "$file_path/fflush_basic.tmp";
44unlink($filename);
45?>
46
47--EXPECTF--
48*** Testing fflush(): writing to a file and reading the contents ***
49int(63)
50bool(true)
51first line of string
52second line of string
53third line of stringint(63)
54
55*** Testing fflush(): for return type ***
56bool(true)
57
58*** Done ***
59