From efc2e158f0be67ff26779c981ac1293c6f6e4ea1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 9 Sep 2016 18:06:30 +0200 Subject: [PATCH] Reduce memory usage in DailyCleanUpCronjob --- .../cronjob/DailyCleanUpCronjob.class.php | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) 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()); } - })); + } } } } -- 2.20.1