Skip to content

Commit 4b4dff5

Browse files
committed
Merge pull request #176 from Geolim4/issue-175
Issue 175
2 parents 8fc8e1f + 175f489 commit 4b4dff5

File tree

4 files changed

+68
-74
lines changed

4 files changed

+68
-74
lines changed

phpfastcache/3.0.0/abstract.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,15 @@ public function getInfoMulti($list = array()) {
175175
return $res;
176176
}
177177

178-
public function deleteMulti($list = array()) {
179-
foreach($list as $array) {
180-
$this->delete($array[0], isset($array[1]) ? $array[1] : array());
178+
public function deleteMulti($list = array(), $option = array()) {
179+
foreach($list as $item) {
180+
if(is_array($item) && count($item) === 2){
181+
$this->delete($item[0], $item[1]);
182+
}else if(is_string($item)){
183+
$this->delete($item, $option);
184+
}else{
185+
throw new Exception('Invalid values passed to deleteMulti()');
186+
}
181187
}
182188
}
183189

@@ -271,7 +277,7 @@ protected function required_extension($name) {
271277

272278
protected function readfile($file) {
273279
if(function_exists("file_get_contents")) {
274-
return @file_get_contents($file);
280+
return file_get_contents($file);
275281
} else {
276282
$string = "";
277283

@@ -327,7 +333,7 @@ protected function decode($value) {
327333
protected function htaccessGen($path = "") {
328334
if($this->option("htaccess") == true) {
329335

330-
if(!@file_exists($path."/.htaccess")) {
336+
if(!file_exists($path."/.htaccess")) {
331337
// echo "write me";
332338
$html = "order deny, allow \r\n
333339
deny from all \r\n
@@ -407,7 +413,7 @@ public function systemInfo() {
407413

408414

409415
protected function isExistingDriver($class) {
410-
if(@file_exists(dirname(__FILE__)."/drivers/".$class.".php")) {
416+
if(file_exists(dirname(__FILE__)."/drivers/".$class.".php")) {
411417
require_once(dirname(__FILE__)."/drivers/".$class.".php");
412418
if(class_exists("phpfastcache_".$class)) {
413419
return true;

phpfastcache/3.0.0/drivers/files.php

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,8 @@ private function getFilePath($keyword, $skip = false) {
5252
* Skip Create Sub Folders;
5353
*/
5454
if($skip == false) {
55-
//if it doesn't exist, I can't create it, and nobody beat me to creating it:
56-
if(!@is_dir($path) && !@mkdir($path,$this->__setChmodAuto()) && !@is_dir($path)) {
57-
throw new Exception("PLEASE CHMOD ".$this->getPath()." - 0777 OR ANY WRITABLE PERMISSION!",92);
58-
}
59-
//if it does exist (after someone beat me to it, perhaps), but isn't writable or fixable:
60-
if(@is_dir($path) && !is_writeable($path) && !@chmod($path,$this->__setChmodAuto())) {
55+
if(!file_exists($path)) {
56+
if(!mkdir($path,$this->__setChmodAuto())) {
6157
throw new Exception("PLEASE CHMOD ".$this->getPath()." - 0777 OR ANY WRITABLE PERMISSION!",92);
6258
}
6359
}
@@ -76,7 +72,7 @@ function driver_set($keyword, $value = "", $time = 300, $option = array() ) {
7672
/*
7773
* Skip if Existing Caching in Options
7874
*/
79-
if(isset($option['skipExisting']) && $option['skipExisting'] == true && @file_exists($file_path)) {
75+
if(isset($option['skipExisting']) && $option['skipExisting'] == true && file_exists($file_path)) {
8076
$content = $this->readfile($file_path);
8177
$old = $this->decode($content);
8278
$toWrite = false;
@@ -91,21 +87,11 @@ function driver_set($keyword, $value = "", $time = 300, $option = array() ) {
9187
* because first-to-lock wins and the file will exist before the writer attempts
9288
* to write.
9389
*/
94-
if($toWrite == true && !@file_exists($tmp_path) && !@file_exists($file_path)) {
90+
if($toWrite == true && !file_exists($tmp_path) && !file_exists($file_path)) {
9591
try {
96-
$f = @fopen($tmp_path, "c");
97-
if ($f) {
98-
if (flock($f,LOCK_EX| LOCK_NB)) {
99-
$written = ($written && fwrite($f, $data));
100-
$written = ($written && fflush($f));
101-
$written = ($written && flock($f, LOCK_UN));
102-
} else {
103-
//arguably the file is being written to so the job is done
104-
$written = false;
105-
}
106-
$written = ($written && @fclose($f));
107-
$written = ($written && @rename($tmp_path,$file_path));
108-
}
92+
$f = fopen($file_path, "w+");
93+
fwrite($f, $data);
94+
fclose($f);
10995
} catch (Exception $e) {
11096
// miss cache
11197
$written = false;
@@ -117,7 +103,7 @@ function driver_set($keyword, $value = "", $time = 300, $option = array() ) {
117103
function driver_get($keyword, $option = array()) {
118104

119105
$file_path = $this->getFilePath($keyword);
120-
if(!@file_exists($file_path)) {
106+
if(!file_exists($file_path)) {
121107
return null;
122108
}
123109

@@ -159,19 +145,18 @@ function driver_stats($option = array()) {
159145

160146
$total = 0;
161147
$removed = 0;
162-
$content = array();
163-
while($file=@readdir($dir)) {
148+
while($file=readdir($dir)) {
164149
if($file!="." && $file!=".." && is_dir($path."/".$file)) {
165150
// read sub dir
166-
$subdir = @opendir($path."/".$file);
151+
$subdir = opendir($path."/".$file);
167152
if(!$subdir) {
168153
throw new Exception("Can't read path:".$path."/".$file,93);
169154
}
170155

171-
while($f = @readdir($subdir)) {
156+
while($f = readdir($subdir)) {
172157
if($f!="." && $f!="..") {
173158
$file_path = $path."/".$file."/".$f;
174-
$size = @filesize($file_path);
159+
$size = filesize($file_path);
175160
$object = $this->decode($this->readfile($file_path));
176161

177162
if(strpos($f,".") === false) {
@@ -219,15 +204,15 @@ function driver_clean($option = array()) {
219204
throw new Exception("Can't read PATH:".$path,94);
220205
}
221206

222-
while($file=@readdir($dir)) {
207+
while($file=readdir($dir)) {
223208
if($file!="." && $file!=".." && is_dir($path."/".$file)) {
224209
// read sub dir
225210
$subdir = @opendir($path."/".$file);
226211
if(!$subdir) {
227212
throw new Exception("Can't read path:".$path."/".$file,93);
228213
}
229214

230-
while($f = @readdir($subdir)) {
215+
while($f = readdir($subdir)) {
231216
if($f!="." && $f!="..") {
232217
$file_path = $path."/".$file."/".$f;
233218
@unlink($file_path);
@@ -240,7 +225,7 @@ function driver_clean($option = array()) {
240225

241226
function driver_isExisting($keyword) {
242227
$file_path = $this->getFilePath($keyword,true);
243-
if(!@file_exists($file_path)) {
228+
if(!file_exists($file_path)) {
244229
return false;
245230
} else {
246231
// check expired or not

phpfastcache/3.0.0/drivers/sqlite.php

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ function initDB(PDO $db) {
3636
function initIndexing(PDO $db) {
3737

3838
// delete everything before reset indexing
39-
$dir = @opendir($this->path);
40-
while($file = @readdir($dir)) {
41-
if($file!="." && $file!=".." && $file!=self::INDEXING_FILE && $file!="dbfastcache") {
42-
@unlink($this->path."/".$file);
39+
$dir = opendir($this->path);
40+
while($file = readdir($dir)) {
41+
if($file != "." && $file!=".." && $file != "indexing" && $file!="dbfastcache") {
42+
unlink($this->path."/".$file);
4343
}
4444
}
4545

@@ -57,7 +57,7 @@ function initIndexing(PDO $db) {
5757
function indexing($keyword) {
5858
if($this->indexing == NULL) {
5959
$createTable = false;
60-
if(!@file_exists($this->path."/".self::INDEXING_FILE)) {
60+
if(!file_exists($this->path."/indexing")) {
6161
$createTable = true;
6262
}
6363

@@ -84,7 +84,7 @@ function indexing($keyword) {
8484

8585
// check file size
8686

87-
$size = @file_exists($this->path."/db".$db) ? @filesize($this->path."/db".$db) : 1;
87+
$size = file_exists($this->path."/db".$db) ? filesize($this->path."/db".$db) : 1;
8888
$size = round($size / 1024 / 1024,1);
8989

9090

@@ -130,7 +130,7 @@ function db($keyword, $reset = false) {
130130
if(!isset($this->instant[$instant])) {
131131
// check DB Files ready or not
132132
$createTable = false;
133-
if(!@file_exists($this->path."/db".$instant) || $reset == true) {
133+
if(!file_exists($this->path."/db".$instant) || $reset == true) {
134134
$createTable = true;
135135
}
136136
$PDO = new PDO("sqlite:".$this->path."/db".$instant);
@@ -169,9 +169,9 @@ function __construct($config = array()) {
169169
$this->fallback = true;
170170
}
171171

172-
if(!@file_exists($this->getPath()."/".self::SQLITE_DIR)) {
173-
if(!@mkdir($this->getPath()."/".self::SQLITE_DIR,$this->__setChmodAuto())) {
174-
$this->fallback = true;
172+
if(!file_exists($this->getPath()."/sqlite")) {
173+
if(!mkdir($this->getPath()."/sqlite",$this->__setChmodAuto())) {
174+
$this->fallback = true;
175175
}
176176
}
177177
$this->path = $this->getPath()."/".self::SQLITE_DIR;
@@ -307,30 +307,33 @@ function driver_stats($option = array()) {
307307
$total = 0;
308308
$optimized = 0;
309309

310-
$dir = @opendir($this->path);
311-
while($file = @readdir($dir)) {
310+
$dir = opendir($this->path);
311+
while($file = readdir($dir)) {
312312
if($file!="." && $file!="..") {
313313
$file_path = $this->path."/".$file;
314-
$size = @filesize($file_path);
315-
$total += $size;
316-
if ($file!=self::INDEXING_FILE) {
317-
try {
318-
$PDO = new PDO("sqlite:".$file_path);
319-
$PDO->setAttribute(PDO::ATTR_ERRMODE,
320-
PDO::ERRMODE_EXCEPTION);
321-
322-
$stm = $PDO->prepare("DELETE FROM `caching` WHERE `exp` <= :U");
323-
$stm->execute(array(
324-
":U" => time(),
325-
));
326-
327-
$PDO->exec("VACUUM;");
328-
$size = @filesize($file_path);
329-
} catch (PDOException $e) {
330-
$res['data'] .= sprintf("%s: %s\n", $file_path, $e->getMessage());
331-
}
332-
}
333-
$optimized += $size;
314+
$size = filesize($file_path);
315+
$total = $total + $size;
316+
317+
try {
318+
$PDO = new PDO("sqlite:".$file_path);
319+
$PDO->setAttribute(PDO::ATTR_ERRMODE,
320+
PDO::ERRMODE_EXCEPTION);
321+
322+
$stm = $PDO->prepare("DELETE FROM `caching` WHERE `exp` <= :U");
323+
$stm->execute(array(
324+
":U" => date("U"),
325+
));
326+
327+
$PDO->exec("VACUUM;");
328+
$size = filesize($file_path);
329+
$optimized = $optimized + $size;
330+
} catch (PDOException $e) {
331+
$size = 0;
332+
$optimized = 0;
333+
}
334+
335+
336+
334337
}
335338
}
336339
$res['size'] = $optimized;
@@ -347,12 +350,12 @@ function driver_clean($option = array()) {
347350
// close connection
348351
$this->instant = array();
349352
$this->indexing = NULL;
350-
351-
// delete everything
352-
$dir = @opendir($this->path);
353-
while($file = @readdir($dir)) {
353+
354+
// delete everything before reset indexing
355+
$dir = opendir($this->path);
356+
while($file = readdir($dir)) {
354357
if($file != "." && $file!="..") {
355-
@unlink($this->path."/".$file);
358+
unlink($this->path."/".$file);
356359
}
357360
}
358361
}

phpfastcache/3.0.0/phpfastcache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ protected static function htaccessGen($path, $create = true) {
248248
throw new Exception("PLEASE CHMOD ".$path." - 0777 OR ANY WRITABLE PERMISSION!",92);
249249
}
250250
}
251-
if(!@file_exists($path."/.htaccess")) {
251+
if(!file_exists($path."/.htaccess")) {
252252
// echo "write me";
253253
$html = "order deny, allow \r\n
254254
deny from all \r\n

0 commit comments

Comments
 (0)