Monday, 28 August 2017

php - Use case for output buffering as the correct solution to "headers already sent"



I see (not just on this site) a lot of question from inexperienced PHP programmers about the infamous "headers already sent... output started at" error, and many people suggest using ouput buffering as a solution.



In my experience I have never found a situation where that error wasn't caused by a flaw in the program's logic. Are there cases where output buffering is actually the correct solution?


Answer



I would concur with your initial statement. Generally, solving "headers" problem with output buffering is a stopgap measure.




The really sad/funny part of this solution is: what happens when you want to output something large, such as a file you are keeping behind a paywall? Usually it results in people replacing the "headers" problem with their scripts running out of memory.



Whoops.


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...