[wp-hackers] Saving the entire HTML sent to client

Dion Hulse (dd32) wordpress at dd32.id.au
Thu Dec 8 02:23:33 UTC 2011


On 8 December 2011 13:18, Haluk Karamete <halukkaramete at gmail.com> wrote:
> We got one of those installed. I think the totla cache. And when it
> was engaged, it was not showing the latest changes I made in the back
> end. Of couese, I had logged in as admin maybe that's the reason?
>
> To get those changes, ( for example to see the output of the latest
> loop I created ), I had to add to the url stuff like q=32113213 to
> avoid caching.

Sounds like you had the caching turned up so high, that pages were
only expires every x minutes rather than on content update.
There are several settings you can set these caching plugins to, from
no caching, up to reddit/slashdot/digg-proof settings.

> With the implementation I suggested however, I was seeking my own
> programmatic solution where I can feel in control and manage the
> caching business in however I want, in whatever chunks I want. But to
> be able to do that, I need to get a hold of the "HTML so far"!
>
> Maybe there is just no way to get a handle of what HTML that the PHP
> functions have generated so far?
>
> Would it be nice to have the option of doing something like this
>
> $content = get_header()
>
> Is this technically not possible?

Yes and no. Yes, It's possible, but you'll have to use output
buffering to catch all output before it's sent to the browser, and
then retrieve/store/send to client the data.
Output buffering is what caching plugins have to use (as there's no other way).

For example:
ob_start();
get_header();
$html = ob_get_clean();

All the HTML output from the get_header call is now stored within
$html and NOT sent to the browser, you'd have to throw an extra echo
$html; in there for that.

In all honesty, The caching plugins out there are miles better than
anything you'll hack together in most cases, they've got time
(sometimes years) of development behind them, and they know what works
and the most efficient way to do it.
In other words: Don't re-invent the wheel when it's probably just
being used incorrectly


More information about the wp-hackers mailing list