From e52cda12163b5e2e650269c35b0f1c401ca0cb67 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Sun, 27 Jul 2014 05:50:23 +0000 Subject: [PATCH] The cache dir must be with 0777, not 0666 ! git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1566 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- cachefile.php | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/cachefile.php b/cachefile.php index 8f6be19..2dd07cf 100644 --- a/cachefile.php +++ b/cachefile.php @@ -6,6 +6,48 @@ class cachefile /** If TRUE : no information is cached */ public $nocache = false; + /** Check if there is some garbage to clean */ + public function garbage () + { + try + { + $this->cachedir (); + } + catch (Exception $e) + { + throw new Exception ($e->getMessage(), $e->getCode()); + } + + $res = $this->read ("CACHE-Garbage"); + if ($res === false) + { + $this->write ("CACHE-Garbage", "Let's go, garbage !", 24*60*60); + $files = glob ($this->directory."/*", GLOB_NOSORT); + foreach ($files as $fileCache) + { + $datas = file_get_contents ($fileCache); + if ($datas === false) + { + unlink ($fileCache); + continue; + } + + $datas = unserialize ($datas); + if (! isset ($datas["ttl"]) || ! isset ($datas["data"]) || + ! isset ($datas["createTime"])) + { + unlink ($fileCache); + continue; + } + + if (($datas["createTime"] + $datas["ttl"]) >= time ()) + { + unlink ($fileCache); + } + } + } + } + /** This function check if the cachedir exists and create it if it is not the case. Check if the cache dir is writable and readable */ @@ -24,7 +66,7 @@ class cachefile if (!mkdir ($this->directory)) throw new Exception (sprintf (_("Can not create cache directory %s"), $this->directory), 500); - chmod ($this->directory, 0666); + chmod ($this->directory, 0777); } if (! is_writable ($this->directory)) throw new Exception (sprintf (_("Cache directory %s is not writable"),