I came across this topic when I was coding around some issues that we had on my forums with some bugs in the Solaris CSK 1.3.1 implementation of APC (see Sun Forums — APC change of behaviour on CSK upgrade). We have a pretty active site running a dozen forums on a common Apache instance, and sharing a common but otherwise reasonably standard phpBB code base (see phpBB3.0.4 Migration — Detailed Implementation Notes if you want more background). I also noticed that my APC cache was being expunged every hour or so, which should really be happening. I also had a problem with cron.php which meant that the cache tidying wasn't being triggered and I pretty quickly accumulated over a quarter of a million cache/sql_* files in just over a day! So I ended up adding the following to my php.ini:
- apc.cache_by_default=1
apc.filters="(/cache/sql_|/cache/data_)"
What I really question is the design choice of keeping the sql_* and data_* cache objects as PHP include fragments, as this has not performance gain and most PHP performance accelerators are simply not optimised to handle such a volume of tiny volatile code fragments. Why not just keep them in .data files as straight serialised text? With such an approach the main load logic in get:
Code: Select all
global $phpEx;
if (!$this->_exists($var_name))
{
return false;
}
@include($this->cache_dir . "data{$var_name}.$phpEx");
return (isset($data)) ? $data : false;
Code: Select all
$temp = @unserialize(file_get_contents($this->cache_dir . 'data{$var_name}.data'));
return ($temp !== false && isset(temp[0]) && time() > $temp[0] && isset(temp[01) )
? $temp[1] : false;
Code: Select all
if ($fp = @fopen($this->cache_dir . "data{$var_name}.$phpEx", 'wb'))
{
@flock($fp, LOCK_EX);
fwrite($fp, "<?php\n\$expired = (time() > " . (time() + $ttl) .
") ? true : false;\nif (\$expired) { return; }\n\n\$data = " .
(sizeof($var) ? "unserialize(" . var_export(serialize($var), true) . ");" : 'array();') . "\n\n?>");
@flock($fp, LOCK_UN);
fclose($fp);
if (!function_exists('phpbb_chmod'))
{
global $phpbb_root_path;
include($phpbb_root_path . 'includes/functions.' . $phpEx);
}
}
phpbb_chmod($this->cache_dir . "data{$var_name}.$phpEx", CHMOD_WRITE);
}
Code: Select all
if (file_put_contents ($this->cache_dir . 'data_{$var_name}.data', serialize(array($ttl, $vars)), LOCK_EX) !== false )
{
if (!function_exists('phpbb_chmod'))
{
global $phpbb_root_path;
include($phpbb_root_path . 'includes/functions.' . $phpEx);
}
}
Regards Terry