From: Tim Düsterhus Date: Fri, 9 Sep 2016 16:06:30 +0000 (+0200) Subject: Reduce memory usage in DailyCleanUpCronjob X-Git-Tag: 3.0.0_Beta_1~237 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=efc2e158f0be67ff26779c981ac1293c6f6e4ea1;p=GitHub%2FWoltLab%2FWCF.git Reduce memory usage in DailyCleanUpCronjob --- diff --git a/wcfsetup/install/files/lib/system/cronjob/DailyCleanUpCronjob.class.php b/wcfsetup/install/files/lib/system/cronjob/DailyCleanUpCronjob.class.php index 67b9c072b2..cc2c8f18d5 100644 --- a/wcfsetup/install/files/lib/system/cronjob/DailyCleanUpCronjob.class.php +++ b/wcfsetup/install/files/lib/system/cronjob/DailyCleanUpCronjob.class.php @@ -166,29 +166,27 @@ class DailyCleanUpCronjob extends AbstractCronjob { // clean up temporary folder $tempFolder = FileUtil::getTempFolder(); - DirectoryUtil::getInstance($tempFolder)->executeCallback(new Callback(function($filename, $object) use ($tempFolder) { - if ($filename === $tempFolder) return; - if ($filename === $tempFolder.'.htaccess') return; + $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($tempFolder, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); + foreach ($it as $file) { + if ($file->getPathname() === $tempFolder) continue; + if ($file->getPathname() === $tempFolder.'/.htaccess') continue; - if ($object->getMTime() < TIME_NOW - 86400) { - if ($object->isDir()) { - @rmdir($filename); - } - else if ($object->isFile()) { - @unlink($filename); - } + if ($file->getMTime() < TIME_NOW - 86400) { + if ($file->isDir()) @rmdir($file->getPathname()); + else if ($file->isFile()) @unlink($file->getPathname()); } - })); + } // clean up proxy images if (MODULE_IMAGE_PROXY) { - DirectoryUtil::getInstance(WCF_DIR.'images/proxy/')->executeCallback(new Callback(function($filename, $object) { - if ($filename === WCF_DIR.'images/proxy/.htaccess') return; + $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(WCF_DIR.'images/proxy/', \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); + foreach ($it as $file) { + if ($file->getPathname() === WCF_DIR.'images/proxy/.htaccess') continue; - if ($object->isFile() && $object->getMTime() < TIME_NOW - 86400 * IMAGE_PROXY_EXPIRATION) { - @unlink($filename); + if ($file->isFile() && $file->getMTime() < (TIME_NOW - 86400 * IMAGE_PROXY_EXPIRATION)) { + @unlink($file->getPathname()); } - })); + } } } }