Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions phpfastcache/3.0.0/abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ public function isExisting($keyword)
* todo: search
* @param $query
* @return mixed
* @throws \Exception
* @throws \phpfastcacheCoreException
*/
public function search($query)
{
if (method_exists($this, "driver_search")) {
return $this->driver_search($query);
}
throw new Exception('Search method is not supported by this driver.');
throw new phpfastcacheCoreException('Search method is not supported by this driver.');
}

/**
Expand Down Expand Up @@ -376,15 +376,15 @@ public function __get($name)
* @param $name
* @param $v
* @return bool|null
* @throws \Exception
* @throws \phpfastcacheCoreException
*/
public function __set($name, $v)
{
if (isset($v[ 1 ]) && is_numeric($v[ 1 ])) {
return $this->set($name, $v[ 0 ], $v[ 1 ],
isset($v[ 2 ]) ? $v[ 2 ] : array());
} else {
throw new Exception("Example ->$name = array('VALUE', 300);", 98);
throw new phpfastcacheCoreException("Example ->$name = array('VALUE', 300);", 98);
}
}

Expand Down Expand Up @@ -424,7 +424,7 @@ protected function required_extension($name)
/**
* @param $file
* @return string
* @throws \Exception
* @throws \phpfastcacheCoreException
*/
protected function readfile($file)
{
Expand All @@ -435,7 +435,7 @@ protected function readfile($file)

$file_handle = @fopen($file, "r");
if (!$file_handle) {
throw new Exception("Can't Read File", 96);
throw new phpfastcacheCoreException("Can't Read File", 96);

}
while (!feof($file_handle)) {
Expand Down Expand Up @@ -488,7 +488,7 @@ protected function decode($value)
/**
* Auto Create .htaccess to protect cache folder
* @param string $path
* @throws \Exception
* @throws \phpfastcacheCoreException
*/
protected function htaccessGen($path = "")
{
Expand All @@ -502,7 +502,7 @@ protected function htaccessGen($path = "")

$f = @fopen($path . "/.htaccess", "w+");
if (!$f) {
throw new Exception("Can't create .htaccess", 97);
throw new phpfastcacheCoreException("Can't create .htaccess", 97);
}
fwrite($f, $html);
fclose($f);
Expand All @@ -526,7 +526,7 @@ protected function isPHPModule()
/**
* return System Information
* @return mixed
* @throws \Exception
* @throws \phpfastcacheCoreException
*/
public function systemInfo()
{
Expand All @@ -536,7 +536,7 @@ public function systemInfo()
$this->option[ 'system' ][ 'drivers' ] = array();
$dir = @opendir(dirname(__FILE__) . "/drivers/");
if (!$dir) {
throw new Exception("Can't open file dir ext", 100);
throw new phpfastcacheCoreException("Can't open file dir ext", 100);
}

while ($file = @readdir($dir)) {
Expand Down
12 changes: 6 additions & 6 deletions phpfastcache/3.0.0/drivers/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct($config = array())
$this->getPath(); // force create path

if (!$this->checkdriver() && !isset($config[ 'skipError' ])) {
throw new Exception("Can't use this driver for your website!");
throw new phpfastcacheDriverException("Can't use this driver for your website!");
}

}
Expand Down Expand Up @@ -78,7 +78,7 @@ private function getFilePath($keyword, $skip = false)
if($skip == false) {
if(!file_exists($path)) {
if(!mkdir($path,$this->__setChmodAuto())) {
throw new Exception("PLEASE CHMOD ".$this->getPath()." - 0777 OR ANY WRITABLE PERMISSION!",92);
throw new phpfastcacheDriverException("PLEASE CHMOD ".$this->getPath()." - 0777 OR ANY WRITABLE PERMISSION!",92);
}
}
}
Expand Down Expand Up @@ -192,7 +192,7 @@ public function driver_stats($option = array())
$path = $this->getPath();
$dir = @opendir($path);
if (!$dir) {
throw new Exception("Can't read PATH:" . $path, 94);
throw new phpfastcacheDriverException("Can't read PATH:" . $path, 94);
}

$total = 0;
Expand All @@ -202,7 +202,7 @@ public function driver_stats($option = array())
// read sub dir
$subdir = opendir($path."/".$file);
if(!$subdir) {
throw new Exception("Can't read path:".$path."/".$file,93);
throw new phpfastcacheDriverException("Can't read path:".$path."/".$file,93);
}

while($f = readdir($subdir)) {
Expand Down Expand Up @@ -264,15 +264,15 @@ public function driver_clean($option = array())
$path = $this->getPath();
$dir = @opendir($path);
if (!$dir) {
throw new Exception("Can't read PATH:" . $path, 94);
throw new phpfastcacheDriverException("Can't read PATH:" . $path, 94);
}

while($file=readdir($dir)) {
if($file!="." && $file!=".." && is_dir($path."/".$file)) {
// read sub dir
$subdir = @opendir($path . "/" . $file);
if (!$subdir) {
throw new Exception("Can't read path:" . $path . "/" . $file,
throw new phpfastcacheDriverException("Can't read path:" . $path . "/" . $file,
93);
}

Expand Down
72 changes: 33 additions & 39 deletions phpfastcache/3.0.0/drivers/sqlite.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public function initIndexing(PDO $db)

// delete everything before reset indexing
$dir = opendir($this->path);
while($file = readdir($dir)) {
if($file != "." && $file!=".." && $file != "indexing" && $file!="dbfastcache") {
unlink($this->path."/".$file);
while ($file = readdir($dir)) {
if ($file != "." && $file != ".." && $file != "indexing" && $file != "dbfastcache") {
unlink($this->path . "/" . $file);
}
}

Expand All @@ -109,7 +109,7 @@ public function indexing($keyword)
{
if ($this->indexing == null) {
$createTable = false;
if(!file_exists($this->path."/indexing")) {
if (!file_exists($this->path . "/indexing")) {
$createTable = true;
}

Expand All @@ -136,8 +136,8 @@ public function indexing($keyword)

// check file size

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


if ($size > $this->max_size) {
Expand Down Expand Up @@ -177,18 +177,18 @@ public function indexing($keyword)
*/
public function db($keyword, $reset = false)
{
/*
/**
* Default is fastcache
*/
$instant = $this->indexing($keyword);

/*
/**
* init instant
*/
if (!isset($this->instant[ $instant ])) {
// check DB Files ready or not
$createTable = false;
if(!file_exists($this->path."/db".$instant) || $reset == true) {
if (!file_exists($this->path . "/db" . $instant) || $reset == true) {
$createTable = true;
}
$PDO = new PDO("sqlite:" . $this->path . "/db" . $instant);
Expand Down Expand Up @@ -233,7 +233,7 @@ public function driver_set(
$time = 300,
$option = array()
) {
$skipExisting = isset($option['skipExisting']) ? $option['skipExisting'] : false;
$skipExisting = isset($option[ 'skipExisting' ]) ? $option[ 'skipExisting' ] : false;
$toWrite = true;

// check in cache first
Expand Down Expand Up @@ -271,14 +271,9 @@ public function driver_set(
} catch (PDOException $e) {
return false;
}

}


}

return false;

}

/**
Expand Down Expand Up @@ -393,30 +388,29 @@ public function driver_stats($option = array())
$optimized = 0;

$dir = opendir($this->path);
while($file = readdir($dir)) {
if($file!="." && $file!="..") {
$file_path = $this->path."/".$file;
while ($file = readdir($dir)) {
if ($file != "." && $file != "..") {
$file_path = $this->path . "/" . $file;
$size = filesize($file_path);
$total = $total + $size;

try {
$PDO = new PDO("sqlite:".$file_path);
$PDO->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);

$stm = $PDO->prepare("DELETE FROM `caching` WHERE `exp` <= :U");
$stm->execute(array(
":U" => date("U"),
));
try {
$PDO = new PDO("sqlite:" . $file_path);
$PDO->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);

$PDO->exec("VACUUM;");
$size = filesize($file_path);
$optimized = $optimized + $size;
} catch (PDOException $e) {
$size = 0;
$optimized = 0;
}
$stm = $PDO->prepare("DELETE FROM `caching` WHERE `exp` <= :U");
$stm->execute(array(
":U" => date("U"),
));

$PDO->exec("VACUUM;");
$size = filesize($file_path);
$optimized = $optimized + $size;
} catch (PDOException $e) {
$size = 0;
$optimized = 0;
}


}
Expand All @@ -438,13 +432,13 @@ public function driver_clean($option = array())

// close connection
$this->instant = array();
$this->indexing = NULL;
$this->indexing = null;

// delete everything before reset indexing
$dir = opendir($this->path);
while($file = readdir($dir)) {
if($file != "." && $file!="..") {
unlink($this->path."/".$file);
while ($file = readdir($dir)) {
if ($file != "." && $file != "..") {
unlink($this->path . "/" . $file);
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions phpfastcache/3.0.0/exceptions/phpfastcacheCoreException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

/**
* phpfastcacheCoreException
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*/
class phpfastcacheCoreException extends Exception
{

}
11 changes: 11 additions & 0 deletions phpfastcache/3.0.0/exceptions/phpfastcacheDriverException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

/**
* phpfastcacheDriverException
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*/
class phpfastcacheDriverException extends Exception
{

}
24 changes: 9 additions & 15 deletions phpfastcache/3.0.0/phpfastcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

require_once(dirname(__FILE__) . "/abstract.php");
require_once(dirname(__FILE__) . "/driver.php");
require_once(dirname(__FILE__) . "/exceptions/phpfastcacheCoreException.php");
require_once(dirname(__FILE__) . "/exceptions/phpfastcacheDriverException.php");

/**
* Short function
Expand Down Expand Up @@ -203,8 +205,7 @@ public static function getPath($skip_create_path = false, $config)
$tmp_dir = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir();
$path = $tmp_dir;
} else {
$path = isset($_SERVER[ 'DOCUMENT_ROOT' ]) ? rtrim($_SERVER[ 'DOCUMENT_ROOT' ],
"/") . "/../" : rtrim(dirname(__FILE__), "/") . "/";
$path = isset($_SERVER[ 'DOCUMENT_ROOT' ]) ? rtrim($_SERVER[ 'DOCUMENT_ROOT' ], "/") . "/../" : rtrim(dirname(__FILE__), "/") . "/";
}

if (self::$config[ 'path' ] != "") {
Expand Down Expand Up @@ -244,8 +245,7 @@ public static function getPath($skip_create_path = false, $config)
@chmod($full_path, self::__setChmodAuto($config));
}
if (!@file_exists($full_path) || !@is_writable($full_path)) {
throw new Exception("PLEASE CREATE OR CHMOD " . $full_path . " - 0777 OR ANY WRITABLE PERMISSION!",
92);
throw new phpfastcacheCoreException("PLEASE CREATE OR CHMOD " . $full_path . " - 0777 OR ANY WRITABLE PERMISSION!", 92);
}
}

Expand Down Expand Up @@ -325,30 +325,24 @@ protected static function htaccessGen($path, $create = true)
{

if ($create == true) {
if (!is_writeable($path)) {
try {
chmod($path, 0777);
} catch (Exception $e) {
throw new Exception("PLEASE CHMOD " . $path . " - 0777 OR ANY WRITABLE PERMISSION!",
92);
if (!is_writable($path)) {
if (!chmod($path, 0777)) {
throw new phpfastcacheCoreException("PLEASE CHMOD " . $path . " - 0777 OR ANY WRITABLE PERMISSION!", 92);
}
}

if(!file_exists($path."/.htaccess")) {
if (!file_exists($path . "/.htaccess")) {
// echo "write me";
$html = "order deny, allow \r\n
deny from all \r\n
allow from 127.0.0.1";

$f = @fopen($path . "/.htaccess", "w+");
if (!$f) {
throw new Exception("PLEASE CHMOD " . $path . " - 0777 OR ANY WRITABLE PERMISSION!",
92);
throw new phpfastcacheCoreException("PLEASE CHMOD " . $path . " - 0777 OR ANY WRITABLE PERMISSION!", 92);
}
fwrite($f, $html);
fclose($f);


}
}

Expand Down