PHP function explanation fflush ()

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

+4
2

fflush() ​​ , flush(), , , .

, , , , . , : linux tail: https://en.wikipedia.org/wiki/Tail_(Unix).

+2

fflush

PHP , fwrite fputcsv. .

, , fputcsv, PHP .

, fflush?

, , fflush fwrite. , , . PHP .

, . fflush PHP Documentaiton

+1

All Articles