Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Basic cache using ob flush

1:05 am on Nov 22, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 28, 2001
posts: 779
votes: 0

Can anyone tell me why this code snippet doesn't work? I have it at the end of my document after everything has been processed. I can get it to work using fopen, but thought I'd try to refine it:
$fileCache = "/home/site/www/cache/acache.html";

if(is_writable($fileCache)) file_put_contents($fileCache, ob_get_flush());


Any ideas? It just doesn't seem to be saving the file.

8:25 pm on Nov 29, 2009 (gmt 0)


WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
votes: 2

Which version of PHP? file_put_contents() was made available in PHP 5 I believe it was. If you have an earlier version of PHP you will have to write your own function or keep using fopen and fwrite, ... which is likely what your own file_put_contents() function will do.
4:07 am on Nov 30, 2009 (gmt 0)

New User

5+ Year Member

joined:Aug 19, 2008
posts: 6
votes: 0

You're flushing the buffer before writing the file so you're writing an empty buffer.

Quote from the manual on ob_flush():

This function will send the contents of the output buffer (if any). If you want to further process the buffer's contents you have to call ob_get_contents() before ob_flush() as the buffer contents are discarded after ob_flush() is called.


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members