Jump to content

Output buffering issue


kcp4911

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.