From 875ada786bf49b765db8cf4f4dff0607f7d5f5b5 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 20 Jun 2013 16:39:49 +0200 Subject: [PATCH] Avoid using GlobIterator since it seems to trip up open_basedir restrictions, fixes #204 --- src/Monolog/Handler/RotatingFileHandler.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Monolog/Handler/RotatingFileHandler.php b/src/Monolog/Handler/RotatingFileHandler.php index cfb0d5aa..0850134d 100644 --- a/src/Monolog/Handler/RotatingFileHandler.php +++ b/src/Monolog/Handler/RotatingFileHandler.php @@ -93,22 +93,20 @@ class RotatingFileHandler extends StreamHandler if (!empty($fileInfo['extension'])) { $glob .= '.'.$fileInfo['extension']; } - $iterator = new \GlobIterator($glob); - $count = $iterator->count(); - if ($this->maxFiles >= $count) { + $logFiles = glob($glob); + if ($this->maxFiles >= count($logFiles)) { // no files to remove return; } // Sorting the files by name to remove the older ones - $array = iterator_to_array($iterator); - usort($array, function($a, $b) { - return strcmp($b->getFilename(), $a->getFilename()); + usort($logFiles, function($a, $b) { + return strcmp($b, $a); }); - foreach (array_slice($array, $this->maxFiles) as $file) { - if ($file->isWritable()) { - unlink($file->getRealPath()); + foreach (array_slice($logFiles, $this->maxFiles) as $file) { + if (is_writable($file)) { + unlink($file); } } }