News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Ilia Alshanetsky's Blog:
PHP's Output Buffering
December 08, 2011 @ 10:01:15

In a new post to his blog Ilia Alshanetsky takes a look at PHP's output buffering feature and some interesting things he found when testing some recent code (hint: it has to do with PHP's "interesting" management of the buffer).

While profiling our application I came across a a rather strange memory usage by the ob_start() function. We do use ob_start() quite a bit to defer output of data, which is a common thing in many applications. What was unusual is that 16 calls to ob_start() up chewing through almost 700kb of memory, given that the data being buffered rarely exceeds 1-2kb, this was quite unusual.

Through a bit more testing he found that, if a buffer provided for content isn't enough, PHP automatically bumps it up by 10kb each time - a waste of resources if you only need a small subset of that. He includes a small patch he made to the PHP core API that allows for defining a custom buffer size and, if it's not enough, bumps up the buffer size by 1kb instead of 10kb.

0 comments voice your opinion now!
output buffer increase patch custom size


blog comments powered by Disqus

Similar Posts

Ilia Alshanetsky's Blog: Scalar Type Hints are Here!

Thomas Weinart: What Iterators Can Do For You

Fabien Potencier's Blog: Create your own framework... on top of the Symfony2 Components (part 7)

Jonathan Snook's Blog: Building a URL Shortener (with CakePHP)

Secunia: Cisco Products PHP "htmlentities()" and "htmlspecialchars()" Buffer Overflows


Community Events





Don't see your event here?
Let us know!


security conference laravel introduction voicesoftheelephpant opinion interview series package composer library symfony community language example podcast tool list framework version

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework