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