Example #1
0
 /**
  * Class constructor
  *
  * Setup Memcache(d)
  *
  * @return void
  */
 public function __construct()
 {
     // Try to load memcached server info from the config file.
     $defaults = $this->_memcacheConf['default'];
     $config = Config::getSoul()->CACHE;
     $memcacheConf = isset($config['MEMCACHED']) ? $config['MEMCACHED'] : null;
     if (is_array($memcacheConf)) {
         $this->_memcacheConf = array();
         foreach ($memcacheConf as $name => $conf) {
             $this->_memcacheConf[$name] = $conf;
         }
     }
     if (class_exists('Memcached', false)) {
         $this->_memcached = new \Memcached();
     } elseif (class_exists('Memcache', false)) {
         $this->_memcached = new \Memcache();
     } else {
         Log::normal('[Error] Failed to create Memcache(d) object; extension not loaded?');
     }
     foreach ($this->_memcacheConf as $cacheServer) {
         isset($cacheServer['HOST']) or $cacheServer['HOST'] = $defaults['HOST'];
         isset($cacheServer['PORT']) or $cacheServer['PORT'] = $defaults['PORT'];
         isset($cacheServer['WEIGHT']) or $cacheServer['WEIGHT'] = $defaults['WEIGHT'];
         if (get_class($this->_memcached) === 'Memcache') {
             // Third parameter is persistance and defaults to TRUE.
             $this->_memcached->addServer($cacheServer['HOST'], $cacheServer['PORT'], true, $cacheServer['WEIGHT']);
         } else {
             $this->_memcached->addServer($cacheServer['HOST'], $cacheServer['PORT'], $cacheServer['WEIGHT']);
         }
     }
     Hook::listen(__CLASS__);
 }
Example #2
0
 /**
  * Initialize the Cache Engine
  *
  * Called automatically by the cache frontend
  * To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
  *
  * @param array $setting array of setting for the engine
  * @return boolean True if the engine has been successfully initialized, false if not
  * @access public
  */
 function init($settings = array())
 {
     if (!class_exists('Memcache')) {
         return false;
     }
     parent::init(array_merge(array('engine' => 'Memcache', 'prefix' => Inflector::slug(APP_DIR) . '_', 'servers' => array('127.0.0.1'), 'compress' => false), $settings));
     if ($this->settings['compress']) {
         $this->settings['compress'] = MEMCACHE_COMPRESSED;
     }
     if (!is_array($this->settings['servers'])) {
         $this->settings['servers'] = array($this->settings['servers']);
     }
     if (!isset($this->__Memcache)) {
         $this->__Memcache =& new Memcache();
         foreach ($this->settings['servers'] as $server) {
             $parts = explode(':', $server);
             $host = $parts[0];
             $port = 11211;
             if (isset($parts[1])) {
                 $port = $parts[1];
             }
             if ($this->__Memcache->addServer($host, $port)) {
                 return true;
             }
         }
         return false;
     }
     return true;
 }
 /**
  * Constructor of the container class.
  *
  * $options can have these keys:
  * 'servers'    an array containing an array: servername, port,
  *              sharedsecret, timeout, maxtries
  * 'configfile' The filename of the configuration file
  * 'authtype'   The type of authentication, one of: PAP, CHAP_MD5,
  *              MSCHAPv1, MSCHAPv2, default is PAP
  *
  * @param  $options associative array
  * @return object Returns an error object if something went wrong
  */
 function Auth_Container_RADIUS($options)
 {
     $this->authtype = 'PAP';
     if (isset($options['authtype'])) {
         $this->authtype = $options['authtype'];
     }
     $classname = 'Auth_RADIUS_' . $this->authtype;
     if (!class_exists($classname)) {
         PEAR::raiseError("Unknown Authtype, please use on of: PAP, CHAP_MD5, MSCHAPv1, MSCHAPv2!", 41, PEAR_ERROR_DIE);
     }
     $this->radius = new $classname();
     if (isset($options['configfile'])) {
         $this->radius->setConfigfile($options['configfile']);
     }
     $servers = $options['servers'];
     if (is_array($servers)) {
         foreach ($servers as $server) {
             $servername = $server[0];
             $port = isset($server[1]) ? $server[1] : 0;
             $sharedsecret = isset($server[2]) ? $server[2] : 'testing123';
             $timeout = isset($server[3]) ? $server[3] : 3;
             $maxtries = isset($server[4]) ? $server[4] : 3;
             $this->radius->addServer($servername, $port, $sharedsecret, $timeout, $maxtries);
         }
     }
     if (!$this->radius->start()) {
         PEAR::raiseError($this->radius->getError(), 41, PEAR_ERROR_DIE);
     }
 }
Example #4
0
 public function __construct($config = [])
 {
     parent::__construct(__NAMESPACE__, $config);
     set_time_limit(0);
     ini_set('memory_limit', '1024M');
     $this->_Worker = new \GearmanWorker();
     foreach ($this->_config['servers'] as $server) {
         $this->_Worker->addServer($server['host'], $server['port']);
     }
     // учитывая, что addServer всегда возвращает true, делаем дополнительный ping сервера для проверки его реакции
     if (!$this->_Worker->echo(self::WORKLOAD_TEST)) {
         throw new Exception('Не удалось соединиться с сервером');
     }
     $this->_Db = new Db($this->_config['Db']);
     // последний рестарт
     $this->_started = $this->_Db->lastRestart();
     if (!empty($this->_function)) {
         if (is_string($this->_function)) {
             $this->_Worker->addFunction($this->_function($this->_function), [$this, 'doJob']);
         } elseif (is_array($this->_function)) {
             foreach ($this->_function as $name => $callback) {
                 $this->_Worker->addFunction($this->_function($name), is_array($callback) ? $callback : [$this, $callback]);
             }
         }
     }
     $this->_Worker->addFunction("restart_{$this->_started}", [$this, 'halt']);
 }
Example #5
0
 /**
  * Initialize the Cache Engine
  *
  * Called automatically by the cache frontend
  * To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
  *
  * @param array $setting array of setting for the engine
  * @return boolean True if the engine has been successfully initialized, false if not
  * @access public
  */
 function init($settings = array())
 {
     if (!class_exists('Memcache')) {
         return false;
     }
     parent::init($settings);
     $defaults = array('servers' => array('127.0.0.1'), 'compress' => false);
     $this->settings = array_merge($this->settings, $defaults, $settings);
     if ($this->settings['compress']) {
         $this->settings['compress'] = MEMCACHE_COMPRESSED;
     }
     if (!is_array($this->settings['servers'])) {
         $this->settings['servers'] = array($this->settings['servers']);
     }
     $this->__Memcache =& new Memcache();
     foreach ($this->settings['servers'] as $server) {
         $parts = explode(':', $server);
         $host = $parts[0];
         $port = 11211;
         if (isset($parts[1])) {
             $port = $parts[1];
         }
         if ($this->__Memcache->addServer($host, $port)) {
             return true;
         }
     }
     return false;
 }
Example #6
0
 /**
  *  Подключение к серверу
  *
  * @param bool $reconnect пепеподключение, если нужно
  * @throws Exception
  * @return bool
  */
 protected function _connect($reconnect = true)
 {
     // уже подключены
     if (!$reconnect && $this->_connected) {
         return $this->_connected;
     }
     // убиваем старое соедение
     unset($this->_Client);
     $this->_connected = false;
     // ну и всё заново
     $this->_Client = new \GearmanClient();
     $server = !empty($this->_config['servers']) && empty($this->_config['server']) ? $this->_config['servers'][0] : $this->_config['server'];
     $this->_Client->addServer($server['host'], $server['port']);
     // учитывая, что addServer всегда возвращает true, делаем дополнительный ping сервера для проверки его реакции
     if (!$this->_Client->ping(self::WORKLOAD_TEST)) {
         throw new Exception('Не удалось соединиться с сервером');
     }
     $this->_connected = true;
     if (is_callable([$this, 'done'])) {
         if (!$this->_Client->setCompleteCallback([$this, 'done'])) {
             throw new Exception('Не удалось установить обработчик');
         }
     }
     if (is_callable([$this, 'exception'])) {
         if (!$this->_Client->setExceptionCallback([$this, 'exception'])) {
             throw new Exception('Не удалось установить обработчик исключений');
         }
     }
     return $this->_connected;
 }
Example #7
0
 /**
  * Constructor
  *
  * @param array $options Options
  */
 public function __construct(array $options)
 {
     parent::__construct($options);
     $this->client = new GearmanClient();
     foreach ($this->_config['servers'] as $server) {
         $this->client->addServer($server);
     }
 }
Example #8
0
 /**
  * 连接服务器
  *
  * @return boolean
  */
 public function connect()
 {
     $this->oCache = new Memcache();
     foreach ($this->aConf as $host) {
         $this->oCache->addServer($host['host'], $host['port']);
     }
     $this->oCache->setCompressThreshold(10000, 0.2);
     return true;
 }
Example #9
0
 /**
  * We open up a connection to each of the memcached servers.
  *
  */
 public function __construct()
 {
     $this->_oDb = new Memcache();
     $aHosts = Phpfox::getParam('core.memcache_hosts');
     $bPersistent = Phpfox::getParam('core.memcache_persistent');
     foreach ($aHosts as $aHost) {
         $this->_oDb->addServer($aHost['host'], $aHost['port'], $bPersistent);
     }
 }
Example #10
0
 /**
  * Start the session.
  *
  * @return mixed NULL if no errors, however FALSE if session cannot start.
  */
 public function init()
 {
     session_set_save_handler(array($this, 'open'), array($this, 'close'), array($this, 'read'), array($this, 'write'), array($this, 'destroy'), array($this, 'gc'));
     $this->_oDb = new Memcache();
     $aHosts = Phpfox::getParam('core.memcache_hosts');
     $bPersistent = Phpfox::getParam('core.memcache_persistent');
     foreach ($aHosts as $aHost) {
         $this->_oDb->addServer($aHost['host'], $aHost['port'], $bPersistent);
     }
     if (!isset($_SESSION)) {
         session_start();
     }
 }
Example #11
0
 /**
  * Constructor
  * @since Version 3.8.7
  * @return void
  */
 public function __construct()
 {
     if (!defined("DS")) {
         define("DS", DIRECTORY_SEPARATOR);
     }
     $path = dirname(dirname(__DIR__)) . DS . "config" . DS . "config.railpage.json";
     if (file_exists($path)) {
         $Config = json_decode(file_get_contents($path));
         $this->host = $Config->Memcached->Host;
         $this->port = $Config->Memcached->Port;
         $this->cn = new PHPMemcached();
         $this->cn->addServer($this->host, $this->port);
     }
 }
 public function __construct($driver, \Liten\Liten $liten = null)
 {
     $this->app = !empty($liten) ? $liten : \Liten\Liten::getInstance();
     if ($driver == 'file') {
         $this->_cache = new \app\src\Core\Cache\etsis_Cache_Filesystem();
     } elseif ($driver == 'apc') {
         $this->_cache = new \app\src\Core\Cache\etsis_Cache_APC();
     } elseif ($driver == 'memcache') {
         /**
          * Filter whether to use `\Memcache`|`\Memcached`.
          *
          * @since 6.2.0
          * @param
          *            bool false Use `\Memcache`|`\Memcached`. Default is false.
          */
         $useMemcached = $this->app->hook->apply_filter('use_memcached', false);
         $this->_cache = new \app\src\Core\Cache\etsis_Cache_Memcache($useMemcached);
         $pool = [['host' => '127.0.0.1', 'port' => 11211, 'weight' => 20]];
         /**
          * Filter the `\Memcache`|`\Memcached` server pool.
          *
          * @since 6.2.0
          * @param array $pool
          *            Array of servers to add to the connection pool.
          */
         $servers = $this->app->hook->apply_filter('memcache_server_pool', $pool);
         $this->_cache->addServer($servers);
     } elseif ($driver == 'external') {
         /**
          * Fires when being used to call another caching system not
          * native to eduTrac SIS.
          *
          * @since 6.2.0
          */
         $this->_cache = $this->app->hook->do_action('external_cache_driver');
     } elseif ($driver == 'xcache') {
         $this->_cache = new \app\src\Core\Cache\etsis_Cache_XCache();
     } elseif ($driver == 'cookie') {
         $this->_cache = new \app\src\Core\Cache\etsis_Cache_Cookie();
     } elseif ($driver == 'json') {
         $this->_cache = new \app\src\Core\Cache\etsis_Cache_JSON();
     } elseif ($driver == 'memory') {
         $this->_cache = new \app\src\Core\Cache\etsis_Cache_Memory();
     }
     if (is_etsis_exception($this->_cache)) {
         return $this->_cache->getMessage();
     }
     return $this->_cache;
 }
Example #13
0
 /**
  * Class constructor
  * 构造函数 类构造器 
  * Setup Memcache(d)
  * 设置Memcache
  * @return	void
  */
 public function __construct()
 {
     // Try to load memcached server info from the config file. 试图加载memcached服务器配置文件的信息。
     $CI =& get_instance();
     $defaults = $this->_memcache_conf['default'];
     if ($CI->config->load('memcached', TRUE, TRUE)) {
         if (is_array($CI->config->config['memcached'])) {
             $this->_memcache_conf = array();
             foreach ($CI->config->config['memcached'] as $name => $conf) {
                 $this->_memcache_conf[$name] = $conf;
             }
         }
     }
     if (class_exists('Memcached', FALSE)) {
         $this->_memcached = new Memcached();
     } elseif (class_exists('Memcache', FALSE)) {
         $this->_memcached = new Memcache();
     } else {
         log_message('error', 'Cache: Failed to create Memcache(d) object未能创建Memcache(d)对象; extension not loaded?扩展不加载?');
     }
     foreach ($this->_memcache_conf as $cache_server) {
         isset($cache_server['hostname']) or $cache_server['hostname'] = $defaults['host'];
         isset($cache_server['port']) or $cache_server['port'] = $defaults['port'];
         isset($cache_server['weight']) or $cache_server['weight'] = $defaults['weight'];
         if (get_class($this->_memcached) === 'Memcache') {
             // Third parameter is persistance and defaults to TRUE. 第三个参数是持久性和默认值为TRUE。
             $this->_memcached->addServer($cache_server['hostname'], $cache_server['port'], TRUE, $cache_server['weight']);
         } else {
             $this->_memcached->addServer($cache_server['hostname'], $cache_server['port'], $cache_server['weight']);
         }
     }
 }
Example #14
0
 /**
  * Class constructor
  *
  * Setup Memcache(d)
  *
  * @return	void
  */
 public function __construct()
 {
     // Try to load memcached server info from the config file.
     $defaults = $this->_config['default'];
     $this->_config = Config::get('cache')->memcached;
     if (class_exists('Memcached', FALSE)) {
         $this->_memcached = new Memcached();
     } elseif (class_exists('Memcache', FALSE)) {
         $this->_memcached = new Memcache();
     } else {
         Logger::logError('Cache: Failed to create Memcache(d) object; extension not loaded?');
         return;
     }
     foreach ($this->_config as $cache_server) {
         isset($cache_server['hostname']) or $cache_server['hostname'] = $defaults['host'];
         isset($cache_server['port']) or $cache_server['port'] = $defaults['port'];
         isset($cache_server['weight']) or $cache_server['weight'] = $defaults['weight'];
         if ($this->_memcached instanceof Memcache) {
             // Third parameter is persistance and defaults to TRUE.
             $this->_memcached->addServer($cache_server['hostname'], $cache_server['port'], TRUE, $cache_server['weight']);
         } elseif ($this->_memcached instanceof Memcached) {
             $this->_memcached->addServer($cache_server['hostname'], $cache_server['port'], $cache_server['weight']);
         }
     }
 }
Example #15
0
 /**
  * Inits memcached server if it needed
  * 
  * @return void
  */
 protected function initMemcached()
 {
     if ($this->storage == 'memcached') {
         $this->memcached = new Memcached();
         $this->memcached->addServer($this->memcachedServer, $this->memcachedPort);
     }
 }
 /**
  * Class constructor
  *
  * Setup Memcache(d)
  *
  * @return    void
  */
 public function __construct()
 {
     // Try to load memcached server info from the config file.
     $CI =& get_instance();
     $defaults = $this->_config['default'];
     if ($CI->config->load('memcached', TRUE, TRUE)) {
         $this->_config = $CI->config->config['memcached'];
     }
     if (class_exists('Memcached', FALSE)) {
         $this->_memcached = new Memcached();
     } elseif (class_exists('Memcache', FALSE)) {
         $this->_memcached = new Memcache();
     } else {
         log_message('error', 'Cache: Failed to create Memcache(d) object; extension not loaded?');
         return;
     }
     foreach ($this->_config as $cache_server) {
         isset($cache_server['hostname']) or $cache_server['hostname'] = $defaults['host'];
         isset($cache_server['port']) or $cache_server['port'] = $defaults['port'];
         isset($cache_server['weight']) or $cache_server['weight'] = $defaults['weight'];
         if ($this->_memcached instanceof Memcache) {
             // Third parameter is persistance and defaults to TRUE.
             $this->_memcached->addServer($cache_server['hostname'], $cache_server['port'], TRUE, $cache_server['weight']);
         } elseif ($this->_memcached instanceof Memcached) {
             $this->_memcached->addServer($cache_server['hostname'], $cache_server['port'], $cache_server['weight']);
         }
     }
 }
 /**
  * Setup memcached.
  *
  * @return	bool
  */
 protected function _setup_memcached()
 {
     // Try to load memcached server info from the config file.
     $CI =& get_instance();
     $defaults = $this->_memcache_conf['default'];
     if ($CI->config->load('memcached', TRUE, TRUE)) {
         if (is_array($CI->config->config['memcached'])) {
             $this->_memcache_conf = array();
             foreach ($CI->config->config['memcached'] as $name => $conf) {
                 $this->_memcache_conf[$name] = $conf;
             }
         }
     }
     if (class_exists('Memcached', FALSE)) {
         $this->_memcached = new Memcached();
     } elseif (class_exists('Memcache', FALSE)) {
         $this->_memcached = new Memcache();
     } else {
         log_message('error', 'Failed to create object for Memcached Cache; extension not loaded?');
         return FALSE;
     }
     foreach ($this->_memcache_conf as $cache_server) {
         isset($cache_server['hostname']) or $cache_server['hostname'] = $defaults['host'];
         isset($cache_server['port']) or $cache_server['port'] = $defaults['host'];
         isset($cache_server['weight']) or $cache_server['weight'] = $defaults['weight'];
         if (get_class($this->_memcached) === 'Memcache') {
             // Third parameter is persistance and defaults to TRUE.
             $this->_memcached->addServer($cache_server['hostname'], $cache_server['port'], TRUE, $cache_server['weight']);
         } else {
             $this->_memcached->addServer($cache_server['hostname'], $cache_server['port'], $cache_server['weight']);
         }
     }
     return TRUE;
 }
 /**
  * Class constructor
  *
  * Setup Memcache(d)
  *
  * @return	void
  */
 public function __construct()
 {
     // Try to load memcached server info from the config file.
     $CI =& get_instance();
     $defaults = $this->_memcache_conf['default'];
     if ($CI->config->load('memcached', TRUE, TRUE)) {
         if (is_array($CI->config->config['memcached'])) {
             $this->_memcache_conf = array();
             foreach ($CI->config->config['memcached'] as $name => $conf) {
                 $this->_memcache_conf[$name] = $conf;
             }
         }
     }
     if (class_exists('Memcached', FALSE)) {
         $this->_memcached = new Memcached();
     } elseif (class_exists('Memcache', FALSE)) {
         $this->_memcached = new Memcache();
     } else {
         throw new RuntimeException('Cache: Failed to create Memcache(d) object; extension not loaded?');
     }
     foreach ($this->_memcache_conf as $cache_server) {
         isset($cache_server['hostname']) or $cache_server['hostname'] = $defaults['host'];
         isset($cache_server['port']) or $cache_server['port'] = $defaults['port'];
         isset($cache_server['weight']) or $cache_server['weight'] = $defaults['weight'];
         if (get_class($this->_memcached) === 'Memcache') {
             // Third parameter is persistance and defaults to TRUE.
             $this->_memcached->addServer($cache_server['hostname'], $cache_server['port'], TRUE, $cache_server['weight']);
         } else {
             $this->_memcached->addServer($cache_server['hostname'], $cache_server['port'], $cache_server['weight']);
         }
     }
 }
Example #19
0
 /**
  * Open the SessionHandler backend.
  *
  * @param   string   $save_path  The path to the session object.
  * @param   string   $name       The name of the session.
  * @return  boolean  True on success, false otherwise.
  */
 public function open($save_path, $name)
 {
     $this->engine = new \Memcached();
     // For each server in the array, we'll just extract the configuration and add
     // the server to the Memcached connection. Once we have added all of these
     // servers we'll verify the connection is successful and return it back.
     foreach ($this->servers as $server) {
         $this->engine->addServer($server['host'], $server['port'], $server['weight']);
     }
     return true;
 }
Example #20
0
 protected function connect($exception = true)
 {
     $host = $this->config['host'];
     $port = $this->config['port'];
     $this->memcache->addServer($host, $port);
     if ($exception) {
         $stats = $this->memcache->getExtendedStats();
         if (!isset($stats["{$host}:{$port}"]) || !$stats["{$host}:{$port}"]) {
             throw new MemcachedException('Can not connect to Memcached server');
         }
     }
     return $this->memcache->connect($host, $port);
 }
Example #21
0
 /**
  * Constructor
  *
  * @return object
  */
 public function __construct()
 {
     if (!extension_loaded('memcached')) {
         throw new Cache_Exception('PHP extension "memcached" not loaded');
     }
     try {
         $servers = explode(',', $this->_config->get('cache/memcached_servers'));
     } catch (Config_KeyNoExist $e) {
         $servers = array();
     }
     if (empty($servers)) {
         $servers = array('localhost:11211');
     }
     // Configure memcached
     $this->memcached = new Memcached();
     foreach ($servers as $server) {
         $split = explode(':', $server);
         if (!isset($split[1])) {
             $split[1] = 11211;
         }
         $this->memcached->addServer($split[0], (int) $split[1]);
     }
 }
Example #22
0
 /**
  * Setup memcached.
  *
  * @return	bool
  */
 protected function _setup_memcached()
 {
     $defaults = array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 1);
     // Try to use user-configured Memcache config, otherwise we'll try
     // to use the defaults
     if (is_array(ee()->config->item('memcached'))) {
         $memcache_config = ee()->config->item('memcached');
     } else {
         $memcache_config = array($defaults);
     }
     // We prefer to use Memcached
     if (class_exists('Memcached', FALSE)) {
         $this->_memcached = new Memcached();
     } elseif (class_exists('Memcache', FALSE)) {
         $this->_memcached = new Memcache();
     } else {
         return FALSE;
     }
     ee()->load->helper('array');
     // Add servers to Memcache
     foreach ($memcache_config as $server) {
         $host = element('host', $server, $defaults['host']);
         $port = element('port', $server, $defaults['port']);
         $weight = element('weight', $server, $defaults['weight']);
         if (get_class($this->_memcached) === 'Memcached') {
             $this->_memcached->addServer($host, $port, $weight);
         } else {
             // Third parameter is persistance and defaults to TRUE.
             $this->_memcached->addServer($host, $port, TRUE, $weight);
         }
     }
     // Check each server to see if it's reporting the time; if at least
     // one server reports the time, we'll consider this driver ok to use
     if (is_array($this->cache_info())) {
         foreach ($this->cache_info() as $server) {
             if (!empty($server['time'])) {
                 // Attempt to get previously-created namespaces and assign to class variable
                 $this->_namespaces = $this->get('namespaces', Cache::GLOBAL_SCOPE, FALSE);
                 return TRUE;
             }
         }
     }
     return FALSE;
 }
 /**
  * Get instance of client benchmarker
  *
  * @throws Exception
  * @param string $client
  * @param string $serializer
  * @return Benchmarker_Memcache|Benchmarker_Memcached|Benchmarker_Redis
  */
 public static function instance($client, $serializer = self::SERIALIZER_PHP)
 {
     switch ($serializer) {
         case self::SERIALIZER_INTERNAL:
         case self::SERIALIZER_IGBINARY:
         case self::SERIALIZER_PHP:
             self::$serializer = $serializer;
             break;
         default:
             throw new Exception('Serializer you passed is currently not supported.');
     }
     switch ($client) {
         case self::CLIENT_PREDIS:
             self::$client = new Predis();
             return new Adapter_Redis();
         case self::CLIENT_REDIS:
             self::$client = new Redis();
             self::$client->connect('127.0.0.1');
             return new Adapter_Redis();
         case self::CLIENT_MEMCACHED:
             self::$client = new Memcached();
             self::$client->addServer('127.0.0.1', 11211);
             return new Adapter_Memcached();
         case self::CLIENT_MEMCACHE:
             self::$client = new Memcache();
             self::$client->addServer('127.0.0.1', 11211);
             return new Adapter_Memcache();
     }
     throw new Exception('Client you passed is currently not supported.');
 }
Example #24
0
 /**
  *  Adds a server to the server pool.
  *
  *  @param string $host                      The hostname of the memcached server.
  *  @param int $weight                       The weight of the server relative
  *                                           to the total weight of all the
  *                                           servers in the pool.
  *                                           This controls the probability of
  *                                           the server being selected for
  *                                           operations, and usually corresponds
  *                                           to the amount of memory available
  *                                           to memcached on that server.
  *  @param int $port                         The port on which memcache is running.
  *                                           (Typically 11211.)
  *  @access public
  *  @return bool
  */
 public function add_server($host, $weight = 0, $port = 11211)
 {
     return $this->_cache->addServer($host, $port, $weight);
 }
Example #25
0
 /**
  * 添加 MEMCACHE 主机
  *
  * @param array $server 
  */
 public function addServer(array $server)
 {
     $this->_memcache->addServer($server['host'], $server['port'], $server['persistent'], $server['weight'], $server['timeout'], $server['retry_interval'], $server['status'], $server['failure_callback']);
 }
Example #26
0
 /**
  * 
  * Adds servers to a memcache connection pool from configuration.
  * 
  * @return void
  * 
  */
 protected function _createPool()
 {
     $connection_count = 0;
     foreach ($this->_config['pool'] as $server) {
         // set all defaults
         $server = array_merge($this->_pool_node, $server);
         // separate addServer calls in case failure_callback is
         // empty
         if (empty($server['failure_callback'])) {
             $result = $this->memcache->addServer((string) $server['host'], (int) $server['port'], (bool) $server['persistent'], (int) $server['weight'], (int) $server['retry_interval'], (bool) $server['status']);
         } else {
             $result = $this->memcache->addServer((string) $server['host'], (int) $server['port'], (bool) $server['persistent'], (int) $server['weight'], (int) $server['retry_interval'], (bool) $server['status'], $server['failure_callback']);
         }
         // Did connection to the last node succeed?
         if ($result === true) {
             $connection_count++;
         }
     }
     // make sure we connected to at least one
     if ($connection_count < 1) {
         throw $this->_exception('ERR_CONNECTION_FAILED', $this->_config['pool']);
     }
 }
Example #27
0
 /**
  * addServer
  * 
  * @param array $config
  */
 public function addServer($config)
 {
     foreach ($config as $v) {
         $this->mc->addServer($v['host'], $v['port'], $v['persistent'], $v['weight'], $v['timeout']);
     }
 }