What is output buffering?

后端 未结 7 2136
不思量自难忘°
不思量自难忘° 2020-11-22 01:49

What is output buffering and why is one using it in PHP?

7条回答
  •  故里飘歌
    2020-11-22 02:42

    Output buffering is used by PHP to improve performance and to perform a few tricks.

    • You can have PHP store all output into a buffer and output all of it at once improving network performance.

    • You can access the buffer content without sending it back to browser in certain situations.

    Consider this example:

    
    

    The above example captures the output into a variable instead of sending it to the browser. output_buffering is turned off by default.

    • You can use output buffering in situations when you want to modify headers after sending content.

    Consider this example:

    
    

提交回复
热议问题