ZF-11684: Zend_Cache_Backend_File large memory usage for cleaning
Description
Class Zend_Cache_Backend_File uses in its _clean() function glob() like this:
$glob = @glob($dir . $prefix . '--*');
This means that all results from a cache folder are stored in memory. For a folder that has many cache files this can lead to memory overflow.
A simple fix for this can be to replace the glob mechanism with simple preg_match:
$handle = opendir($dir);
if (!$handle) {
return false;
}
$prefixEscaped = str_replace('/', '\/', $prefix);
while (false !== ($fileName = readdir($handle))) {
if (!preg_match('/^' . $prefixEscaped . '\-\-/', $fileName)) {
continue;
}
$file = $dir . $fileName;
// ...
}
closedir($handle);
Comments
Posted by Marc Bennewitz (private) (mabe) on 2012-01-09T20:19:22.000+0000
On ZF2 it's already fixed by using the class GlobIterator instead of the raw glob function. But the GlobIterator isn't available before PHP 5.3.
Using opendir + preg_match could help but it's in as glob in definition.