I want to create a cache. At the beginning of my php index, I use :
if ($docache) {
$folder_cache = dirname(__FILE__).'/cache/';
$seconds_cache = 15*60; // 15 minutes
$url_cache = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$file_cache = $folder_cache . md5($url_cache) . '.cache';
$file_cache_existe = ( @file_exists($file_cache) ) ? @filemtime($file_cache) : 0;
if ($file_cache_existe > time() - $seconds_cache ) {
@readfile($file_cache);
exit();
}
}
ob_start();
Then, at the end :
if ($docache) {
$folder_cache = dirname(__FILE__).'/cache/';
$url_cache = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$file_cache = $folder_cache . md5($url_cache) . '.cache';
$filehandler = @fopen($file_cache, 'w');
@fwrite($filehandler, ob_get_contents());
@fclose($filehandler);
}
Well, it works... The cache file is created when we see the page for the first time, and then we go back, it displays the file in cache... The problem is that the file in cache contains only some unreadable characters like ��<�r㶒�V��.
Seems to be like if the ob_get_contents function returns that instead of what is truely displayed ? I really don't understand why !
You could start off by removing the error suppression and inspecting what the output is.
It is probable that you are encountering a character encoding issue.