This technique is an old one. Feed your content through the PHP output buffer using the gzip handler, then at the end flush it out to the browser.
Even if the text doesn’t compress well, just using the output buffer results in slightly less network traffic as the data is sent in one big blob. I have to investigate if the HTTP headers are affected yet but it seems to be working fine.