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 = __DIR__;
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--CLEAN--
40<?php
41$file_path = __DIR__;
42$filename = "$file_path/fflush_basic.tmp";
43unlink($filename);
44?>
45--EXPECT--
46*** Testing fflush(): writing to a file and reading the contents ***
47int(63)
48bool(true)
49first line of string
50second line of string
51third line of stringint(63)
52
53*** Testing fflush(): for return type ***
54bool(true)
55
56*** Done ***
57