Use case for output buffering as the correct solution to “headers already sent”

前端 未结 5 570
无人及你
无人及你 2020-12-11 17:10

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 su

5条回答
  •  抹茶落季
    2020-12-11 18:09

    The only situation I can imagine is a CMS or Weblog in which plugins can be invoked in the HTML code, like

    My images

    {plugin:show_images}

    those plugins may have to add their own style sheets and other things that go in the section of the page. Using buffering, this would be possible.

    In practice though, this is not good for performance, feels kludgy and doesn't work when output buffering is turned off. Even here, it is therefore better to pre-process the contents before showing them, and doing any adding of style sheets etc. before anything is output.

提交回复
热议问题