News for hackers. Stuff that matters.
Re:PHP's ob_start() pre-allocates 40k memory per call by itmag on Thursday December 08, 2011 @03:08AM (#3328228)
I would think the BEST way in theory would be to not output strings at all but rather build some kind of logical representation via datastructures (ie a DOM tree as in JQuery or HTML templates which are tied to a code-behind as in ASP.NET) and then output that after all processing is done.

What's the best PHP framework/library for that kind of thing?

Re:PHP's ob_start() pre-allocates 40k memory per call by dexen on Thursday December 08, 2011 @04:12AM (#3328379)
Funny you should ask that. There's that popular templating framework that is really good at transforming a flat or tree-ish structure of arrays and objects into a flat string. Also has a nice textual persistence format which lets you mix XML literals with processing instructions; well supported by most text editors out there. The framework is not all that great for other uses, but really shines at templating. You mix and match botch standard DOM -- including XSLT and whatnot -- and its fast, simple native arrays and objects. Available on many servers. The framework originally targetted Perl, but later on was re-implemented in C as standalone entity, for better performance.

They call it `PHP'.

Re:PHP's ob_start() pre-allocates 40k memory per call by sirclueless on Thursday December 08, 2011 @03:47AM (#3328315)
Ummm, all of them?

The basic problem you run into is that PHP is basically a templating language at its heart. If you don't immediately open with a "<?" you start sending data. If you want to use PHP as it was originally intended -- as raw HTML with a smattering of dynamic bits in the middle -- without losing the ability to set headers, then ob_start makes sense. If on the other hand you want to use it in the way that most people do, you open with "<?php" and proceed to abuse a whole bunch of bastardized perl templating functions followed by an "echo $data; ?>" at the end of your source code.

Now, given that PHP as a templating language is basically terrible, it's not that far out to just say, "To hell with PHP's native templating features, we're going to use our own!" but at that point you are already pretty far gone.

Re:PHP's ob_start() pre-allocates 40k memory per call by wvenable on Thursday December 08, 2011 @11:55AM (#3329859)
Actually that's not necessarily the best way because it's very memory intensive. Imagine a 50 line table containing text columns, link columns, images, buttons. That is a lot of objects in a DOM representation. A procedural loop generating the same table is significantly faster and smaller (but harder to work with). I've found the best thing is some combination -- some data structures and some flat procedural processing.