The manual says that it removes the output to a file. Plus they give an example.
$filename = 'bar.txt';
$file = fopen($filename, 'r+');
rewind($file);
fwrite($file, 'Foo');
fflush($file);
ftruncate($file, ftell($file));
fclose($file);
I tried to understand its necessity. I have done the following:
- I created a bar.txt file
- I ran the script
- I opened bar.txt and saw "Foo" inside it, after which I again made the file empty.
- Then ... I removed
fflush($file);from the script and ran it again. - The result was exactly the same. I made the file empty again.
- After that I changed the line
frwite()tofwrite($file, 'Foo'); die(); - Again ... the same results ... file with "foo" inside it.
Now I see no reason to use fflush().
I do not see the need for fflush in this example. Can you give an example that really requires fflush().
:
http://php.net/manual/en/function.fflush.php