kcp4911 Posted April 25, 2010 Share Posted April 25, 2010 Hi. I am only new to the output buffering business but I found a pretty handy tutorial at http://articles.sitepoint.com/article/caching-php-performance which I have used (it references an article on this site which I cannot find). The code I have cobbled together seems to work about 98% ok. However, there is one problem (so far). I have one page that I have split up into about 6 chunks for buffering - each with different expiry times. The longest cache is 24 hours and the shortest is 10mins. The problem occurs when the page is loaded for the first time after the cached version of the file with the shortest cache expiry is refreshed. The page is rendered in a garbled fashion. Reloading straight away fixes the problem and the page is rendered correctly. I suspect the problem lies in the file writing process when the expired file is re-cached. I have been using the following functions for reading and writing the cache files... function writeCache($content, $filename) { $fp = fopen('./cache/' . $filename, 'w'); flock($fp, LOCK_EX); fwrite($fp, $content); flock($fp, LOCK_UN); fclose($fp); } function readCache($filename, $expiry) { if (file_exists('./cache/' . $filename)) { if ((time() - $expiry) > filemtime('./cache/' . $filename)) { return false; } $cache = file('./cache/' . $filename); return implode('', $cache); } return false; } thanks for your help in advance simon Link to comment https://forums.phpfreaks.com/topic/199665-output-buffering-issue/ Share on other sites More sharing options...
kcp4911 Posted April 25, 2010 Author Share Posted April 25, 2010 seems to have been affected by a duplicate variable in another file - I think Link to comment https://forums.phpfreaks.com/topic/199665-output-buffering-issue/#findComment-1048047 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.