Is excessive buffering required in PHP?

When performance is important, including server memory, I'm curious to use output buffering as ob_start (); in PHP ANY performance gains not used? Does he use more memory or something else to use it?

In my situation on a high-traffic site, where I need all the memory that I can use for memcache and APC and all other server actions, I just wonder if I will use it or not, the only real reason I'm comfortable to redirect pages, send headers that I have to say after the header has already been sent, my site has a header, body, footer setting, so sometimes I need to redirect depending on what is in the main file, so if agolovok already shown an ion screen that creates the problem, using the output buffering - 1 solution, but there are other solutions that are just interested in the performance of

+7
php output-buffering
source share
2 answers

I think it’s better to use it with a high traffic site or at least turn off a hidden reset to avoid sending partial responses over the network, as it can slow down the rest of the script if the receiver is very slow too.

By sending the entire response in one go, you free up all the resources used by the php script, so it is more efficient.

+1
source share

There are two reasons why it is useful to use output buffering.

  • For performance, so you are not expecting when the network socket will be every time you echo.
  • To not send headers too early. Once you have sent content to the browser, the headers should also be sent after that, you cannot change them, for example, if you want to set a cookie or change the type of content.

Of course, there is a penalty for storing everything in memory until the end of the request. Usually this should be quite small compared to the overall size of the PHP process. That is, if you do not plan to send a massive file via cable. If this is the case, you can periodically flush the buffer using ob_flush () and flush () (or temporarily disable the buffer as a whole) to reduce peak memory usage.

In my opinion, you should have it all the time and delete it in exceptional cases.

+3
source share

All Articles