1

I've got stuck with the concept of 'Output Buffer' in PHP.

I was learning the concept of File Handling in PHP from the URL PHP 5 FIle Handling

There I come across the following code :

<!DOCTYPE html>
<html>
  <body>

  <?php
    echo readfile("webdictionary.txt");
  ?>

  </body>
</html>

The explanation of above code was given like this "The readfile() function reads a file and writes it to the output buffer."

I didn't understand where the 'Output Buffering' is used in above code.

Then I searched the PHP manual for the word Output Buffer but it said output buffer doesn't exist.

Then I searched stackoverflow, got one question but it also didn't clear me what exactly the thing 'Output Buffer' is and when to use it and why to use it? Also, is it same as clipboard?

What are the advantages and disadvantages(if any) of using 'Output Buffer'?

Please clear all of my doubts in simple and lucid language.

Note : Please don't mark my question as duplicate because in other questions that are present on stackoverflow Output Buffering is explained in hard to understand manner along with the complicated headers concept which I didn't understand at all. I want to know Output Buffer and not Output Buffering. So, please try to answer my doubts.

Thank You.

PHPLover
  • 1
  • 51
  • 158
  • 311
  • @Joe Watkins: As I've already explained properly in my question that how my question is different from that question. Please remove the duplicate tag on my question. Than You. – PHPLover Aug 10 '17 at 09:12
  • 1
    For performance reasons, the I/O operations always use buffers. This happens everywhere, not just in PHP. The data generated by the PHP script is stored in a memory buffer (for output) and it is sent back to the browser when the buffer is full or when the PHP script uses [`flush()`](http://php.net/manual/en/function.flush.php). This is, indeed, a different thing than the [output buffering](http://php.net/manual/en/function.ob-start.php) controlled using the `ob_*()` functions. – axiac Aug 10 '17 at 11:32
  • @axiac :Thanks for understanding my exact problem. Would you please vote for reopen the question so that anyone can answer. – PHPLover Aug 10 '17 at 11:38
  • 1
    The answer to your question is partially exposed in the documentation of [`flush()`](http://php.net/manual/en/function.flush.php). There is not much more to say about it. The data to be written in a file by [`fwrite()`](http://php.net/manual/en/function.fwrite.php), f.e. is also buffered (in a different buffer though) a.s.o. – axiac Aug 10 '17 at 11:42

0 Answers0