Issues

ZF-11684: Zend_Cache_Backend_File large memory usage for cleaning

Issue Type: Improvement Created: 2011-08-18T16:23:26.000+0000 Last Updated: 2012-01-09T20:19:28.000+0000 Status: Open Fix version(s): Reporter: Cristian Radu (indy2kro) Assignee: Marc Bennewitz (private) (mabe) Tags: - Zend_Cache

  • cache
  • caching

Related issues: Attachments:

Description

Class Zend_Cache_Backend_File uses in its _clean() function glob() like this:

<pre class="highlight"> 
$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:

<pre class="highlight">
        $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.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts