24h $cachePath = 'cache'; if(file_exists($cachePath)){ $cacheIterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($cachePath), RecursiveIteratorIterator::CHILD_FIRST ); foreach($cacheIterator as $cacheFile){ if(in_array($cacheFile->getBasename(), array('.', '..'))) continue; elseif($cacheFile->isFile()){ if(filemtime($cacheFile->getPathname()) < $cacheTimeLimit) unlink($cacheFile->getPathname()); } } } } }