Ejemplo n.º 1
0
 /**
  * Class constructor
  *
  * @param   string          $server         Server address (or IP)
  * @param   string          $port           (optional) Server port
  * @param   string          $weight         (optional) Server weight
  * @param   string          $persistent_id  (optional) Persistent id
  * @param   \Monolog\Logger $logger         Logger instance
  * 
  * @throws \Comodojo\Exception\CacheException
  */
 public function __construct($server, $port = 11211, $weight = 0, $persistent_id = null, \Monolog\Logger $logger = null)
 {
     if (empty($server)) {
         throw new CacheException("Invalid or unspecified memcached server");
     }
     if (!is_null($persistent_id) && !is_string($persistent_id)) {
         throw new CacheException("Invalid persistent id");
     }
     if (self::getMemcachedStatus() === false) {
         $this->raiseError("Memcached extension not available, disabling cache administratively");
         $this->disable();
         return;
     }
     $this->instance = new Memcached($persistent_id);
     $port = filter_var($port, FILTER_VALIDATE_INT, array("options" => array("min_range" => 1, "max_range" => 65535, "default" => 11211)));
     $weight = filter_var($weight, FILTER_VALIDATE_INT, array("options" => array("min_range" => 0, "default" => 0)));
     $this->addServer($server, $port, $weight);
     if ($this->isEnabled()) {
         try {
             parent::__construct($logger);
         } catch (CacheException $ce) {
             throw $ce;
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Class constructor
  *
  * @throws \Comodojo\Exception\CacheException
  */
 public function __construct(\Monolog\Logger $logger = null)
 {
     try {
         parent::__construct($logger);
     } catch (CacheException $ce) {
         throw $ce;
     }
     if (self::getApcStatus() === false) {
         $this->raiseError("Apc extension not available, disabling cache administratively");
         $this->disable();
     }
 }
Ejemplo n.º 3
0
 /**
  * Class constructor
  *
  * @throws \Comodojo\Exception\CacheException
  */
 public function __construct($cache_folder = null, \Monolog\Logger $logger = null)
 {
     if (!empty($cache_folder) && is_string($cache_folder)) {
         $this->cache_folder = $cache_folder[strlen($cache_folder) - 1] == "/" ? $cache_folder : $cache_folder . "/";
     } else {
         if (defined("COMODOJO_CACHE_FOLDER")) {
             $folder = COMODOJO_CACHE_FOLDER;
             $this->cache_folder = $folder[strlen($folder) - 1] == "/" ? $folder : $folder . "/";
         } else {
             throw new CacheException("Invalid or unspecified cache folder");
         }
     }
     if (self::checkCacheFolder($this->cache_folder) === false) {
         $this->raiseError("Cache folder not writeable, disabling cache administratively");
         $this->disable();
     } else {
         try {
             parent::__construct($logger);
         } catch (CacheException $ce) {
             throw $ce;
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Class constructor
  *
  * @param   string          $server         Server address (or IP)
  * @param   integer         $port           (optional) Server port
  * @param   integer         $timeout        (optional) Timeout
  * @param   \Monolog\Logger $logger         Logger instance
  * 
  * @throws \Comodojo\Exception\CacheException
  */
 public function __construct($server, $port = 6379, $timeout = 0, \Monolog\Logger $logger = null)
 {
     if (empty($server)) {
         throw new CacheException("Invalid or unspecified memcached server");
     }
     if (self::getRedisStatus() === false) {
         $this->raiseError("PhpRedis extension not available, disabling cache administratively");
         $this->disable();
         return;
     }
     $this->instance = new Redis();
     $port = filter_var($port, FILTER_VALIDATE_INT, array("options" => array("min_range" => 1, "max_range" => 65535, "default" => 6379)));
     $weight = filter_var($timeout, FILTER_VALIDATE_INT, array("options" => array("min_range" => 0, "default" => 0)));
     if ($this->instance->connect($server, $port, $weight) === false) {
         $this->raiseError("Error communicating with server", array($this->instance->getLastError()));
         $this->disable();
     } else {
         try {
             parent::__construct($logger);
         } catch (CacheException $ce) {
             throw $ce;
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Class constructor
  * 
  * @param   \Comodojo\Database\EnhancedDatabase $dbh    
  * @param   string                              $table          Name of table
  * @param   string                              $table_prefix   Prefix for table
  * @param   \Monolog\Logger                     $logger         Logger instance
  *
  * @throws \Comodojo\Exception\CacheException
  */
 public function __construct(EnhancedDatabase $dbh, $table = null, $table_prefix = null, \Monolog\Logger $logger = null)
 {
     if (!empty($table)) {
         $this->table = $table;
     } else {
         if (defined("COMODOJO_CACHE_DATABASE_TABLE")) {
             $this->table = COMODOJO_CACHE_DATABASE_TABLE;
         } else {
             throw new CacheException("Database table cannot be undefined");
         }
     }
     if (empty($table_prefix)) {
         $this->table_prefix = defined("COMODOJO_CACHE_DATABASE_TABLEPREFIX") ? COMODOJO_CACHE_DATABASE_TABLEPREFIX : null;
     } else {
         $this->table_prefix = $table_prefix;
     }
     $this->dbh = $dbh;
     $this->dbh->autoClean();
     try {
         parent::__construct($logger);
     } catch (CacheException $ce) {
         throw $ce;
     }
 }