1

According to GET parameters, I want to save the output HTML and save to my own cache. Next time it's called, load the cache. It sounds easy to use ob_start() and ob_get_contents() but what if the other running scripts in between use this too? It spoils the "original" output buffering, right?

How to globally save the output?

5
  • don't put in cache whole page, cache only data, which should be fetched from database. Commented Jul 30, 2011 at 16:59
  • 4
    don't cache only data, cache the whole page. ;D Commented Jul 30, 2011 at 17:00
  • 1
    I'm with Jens on this: Cache the whole page. Reading stuff from the database is just as fast as reading it from a file. Just remember "There are only two hard things in Computer Science: cache invalidation and naming things" (Phil Karlton). So be sure you know when to rewrite the cache file(s) Commented Jul 30, 2011 at 17:15
  • 1
    @Flambino Reading stuff from the database is just as fast as reading it from a file. - you just noob. Nothing personal. And caching in files is almost most stupid kind of caching. Commented Jul 31, 2011 at 14:37
  • @OZ_: could you explain more? Caching an entire PHP page instead of re-processing it each time doesn't make sense to you? Even if the PHP file does not access the DB? Commented Apr 2, 2012 at 12:23

1 Answer 1

2

To quote the PHP manual for ob_start:

Output buffers are stackable, that is, you may call ob_start() while another ob_start() is active. Just make sure that you call ob_end_flush() the appropriate number of times.

In other words: No, it doesn't spoil the original output buffering; buffering can be nested. You can also use ob_get_flush() instead of ob_end_flush() to "stop" buffering.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.