stripping with an OB callback

From: Date: Thu, 21 Sep 2006 00:13:29 +0000
Subject: stripping with an OB callback
Groups: php.general 
Request: Send a blank email to php-general+get-242000@lists.php.net to get a copy of this message
I've been coding with PHP for maybe a year. So I'm somewhat new to it. But I've learned quickly, and created a fairly serious LAMP app that is capable of returning large query results. During my investigation into various means for incrementally reducing the response sizes, I've discovered output buffering with a callback function. So, as an experiment, I bracketed my includes of the Fusebox files in index.php with ob_start('sweeper') and ob_end_flush(), and placed the simple callback function at the top of the file that performs a preg_replace on the buffer to strip all excess space: function sweeper($buffer) { return preg_replace("/\s\s+/", " ", $buffer); } Results? Kinda nice! A large query result measuring over 900K of HTML is reduced to 600K. With no change at the browser. Still valid HTML, and the browser happily gobbles it up and displays it cleanly. It's just 30% faster getting to me. Now, the question. Is this going to bite me in the ass? 'Cause right now, it looks dang good to me. Great bang for the buck, as far as I'm concerned. I've been churning it over in my head, and I don't see a situation (certainly not in my particular app) where doing this whitespace reduction is going to backfire. There isn't anything in any of this that requires the contiguous non-word characters. I have a feeling though, that one of you more learned PHPers are going to tell me exactly where my ass is gonna start hurtin'. Christopher Watson Principal Architect The International Variable Star Index (VSX) http://vsx.aavso.org

« previous php.general (#242000) next »