[wp-hackers] output buffering in general and wordpress

Dion Hulse (dd32) wordpress at dd32.id.au
Thu May 3 06:39:26 UTC 2012


On 3 May 2012 16:22, Stas Sușcov <stas at nerd.ro> wrote:
> În data de Thu, 03 May 2012 04:06:11 +0300, Dion Hulse (dd32)
> <wordpress at dd32.id.au> a scris:
>
>
>>
>> tl;dr: Avoid output buffering if at all possible, It's faster for web
>> apps to send data over the wire as it's generated, saves memory
>> footprint, saves latency, gets the browser rendering things faster,
>> etc.
>>
>>
>
> This is debatable[1][2] and mostly not true[3].
>
> Beside caching and gzip-ing, a reason to use output buffering is in case of
> a template engine[4].
>
> [1]:
> http://stackoverflow.com/questions/1556613/php-output-buffering-sounds-like-a-bad-idea-is-it
> [2]:
> http://stackoverflow.com/questions/4731375/is-using-output-buffering-considered-a-bad-practice
> [3]: https://developers.google.com/speed/articles/optimizing-php
> [4]: https://github.com/fabpot/Twig/blob/master/lib/Twig/Template.php

Number 3 is a extremely poor article/reasoning for output buffering,
If anything, It's suggesting that output buffering in the way
generally used in the PHP world is a bad thing.
What it does suggest, is that the output buffering configuration
should be tweaked to send chunks of data sooner rather than later,
which is the opposite of most php output buffers.

Most web servers will have a builtin output buffer to send the data in
reasonable sized chunks as well, each servers defaults are different,
and each can be configured differently.
For example, apache with mod_deflate enabled has a 8K buffer - that
is, It reads 8K from the source (PHP, FastCGI, static content, etc)
compresses that, and sends it over the wire.

Links 1 and 2 also have a similar issue, The content they quote saying
it's a advantage is actually advocating disabling full page output
buffers, and flushing buffers early to speed up data being sent over
the wire for faster rendering by the client.

Finally, yes, there are places where output buffering is useful - to
catch echo'd content directly to alter it or cache it, infact, this is
what most WordPress caching plugins do (well, all of them do it). But
you have to be doing it for a reason for it to be of use.. caching and
some template engines require it, general programming though? It
shouldn't need it at all.

Running full page output buffering - that is, storing every bit of
HTML output from a script into a variable in memory before sending it
to the client, is not going to be of benefit in general, and will
simply lead to more resources being used, and a slower site as a
result.

tl'dr: I disagree with all of the links in the way you're interpreted them.


More information about the wp-hackers mailing list