homepage Welcome to WebmasterWorld Guest from 50.19.33.5
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Accredited PayPal World Seller

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Basic cache using ob flush
madmatt69




msg:4029474
 1:05 am on Nov 22, 2009 (gmt 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:
<?php
$fileCache = "/home/site/www/cache/acache.html";
ob_flush();

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

?>

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

 

coopster




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

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.

tfk11




msg:4033848
 4:07 am on Nov 30, 2009 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved