Esempio n. 1
0
 /**
  * Constructor
  *
  * @access protected
  * @param array $options optional parameters
  */
 function __construct($options = array())
 {
     if (!$this->test()) {
         return JError::raiseError(404, "The memcache extension is not available");
     }
     parent::__construct($options);
     $config =& JFactory::getConfig();
     $params = $config->getValue('config.memcache_settings');
     if (!is_array($params)) {
         $params = unserialize(stripslashes($params));
     }
     if (!$params) {
         $params = array();
     }
     $this->_compress = isset($params['compression']) ? $params['compression'] : 0;
     $this->_persistent = isset($params['persistent']) ? $params['persistent'] : false;
     // This will be an array of loveliness
     $this->_servers = isset($params['servers']) ? $params['servers'] : array();
     // Create the memcache connection
     $this->_db = new Memcache();
     for ($i = 0, $n = count($this->_servers); $i < $n; $i++) {
         $server = $this->_servers[$i];
         $this->_db->addServer($server['host'], $server['port'], $this->_persistent);
     }
     // Get the site hash
     $this->_hash = $config->getValue('config.secret');
 }
Esempio n. 2
0
 /**
  * Open the SessionHandler backend.
  *
  * @param   string  $save_path     The path to the session object.
  * @param   string  $session_name  The name of the session.
  *
  * @return  boolean  True on success, false otherwise.
  *
  * @since   11.1
  */
 public function open($save_path, $session_name)
 {
     $this->_db = new Memcached();
     for ($i = 0, $n = count($this->_servers); $i < $n; $i++) {
         $server = $this->_servers[$i];
         $this->_db->addServer($server['host'], $server['port'], $this->_persistent);
     }
     return true;
 }
 /**
  * Initialise this new cell collection
  *
  * @param    PHPExcel_Worksheet $parent The worksheet for this cell collection
  * @param                       array   of mixed        $arguments    Additional initialisation arguments
  */
 public function __construct(PHPExcel_Worksheet $parent, $arguments)
 {
     $memcacheServer = isset($arguments['memcacheServer']) ? $arguments['memcacheServer'] : 'localhost';
     $memcachePort = isset($arguments['memcachePort']) ? $arguments['memcachePort'] : 11211;
     $cacheTime = isset($arguments['cacheTime']) ? $arguments['cacheTime'] : 600;
     if (is_null($this->_cachePrefix)) {
         $baseUnique = $this->_getUniqueID();
         $this->_cachePrefix = substr(md5($baseUnique), 0, 8) . '.';
         //	Set a new Memcache object and connect to the Memcache server
         $this->_memcache = new Memcache();
         if (!$this->_memcache->addServer($memcacheServer, $memcachePort, false, 50, 5, 5, true, array($this, 'failureCallback'))) {
             throw new PHPExcel_Exception('Could not connect to MemCache server at ' . $memcacheServer . ':' . $memcachePort);
         }
         $this->_cacheTime = $cacheTime;
         parent::__construct($parent);
     }
 }
Esempio n. 4
0
 /**
  * 构造函数
  *
  * @param 缓存策略 $policy
  */
 function cache_memcached(array $policy = null)
 {
     if (!extension_loaded('memcache')) {
         exit('The memcache extension must be loaded before use!');
     }
     if (is_array($policy)) {
         $this->_default_policy = array_merge($this->_default_policy, $policy);
     }
     if (empty($this->_default_policy['servers'])) {
         $this->_default_policy['servers'][] = $this->_default_server;
     }
     $this->_conn = new Memcache();
     foreach ($this->_default_policy['servers'] as $server) {
         $result = $this->_conn->addServer($server['host'], $server['port'], $this->_default_policy['persistent']);
         if (!$result) {
             exit(sprintf('Connect memcached server [%s:%s] failed!', $server['host'], $server['port']));
         }
     }
 }
Esempio n. 5
0
 /**
  * Constructor
  *
  * @param array $config an array of configuration params
  *
  * @return \CRM_Utils_Cache_Memcached
  */
 function __construct($config)
 {
     if (isset($config['host'])) {
         $this->_host = $config['host'];
     }
     if (isset($config['port'])) {
         $this->_port = $config['port'];
     }
     if (isset($config['timeout'])) {
         $this->_timeout = $config['timeout'];
     }
     if (isset($config['prefix'])) {
         $this->_prefix = $config['prefix'];
     }
     $this->_cache = new Memcached();
     if (!$this->_cache->addServer($this->_host, $this->_port)) {
         // dont use fatal here since we can go in an infinite loop
         echo 'Could not connect to Memcached server';
         CRM_Utils_System::civiExit();
     }
 }
Esempio n. 6
0
 /**
  * Устанавливает соединение с сервером memcached и сохраняет ресурс подключения в $this->memcached
  * Если соединение существует, то переподключения не происходит.
  * 
  * @return boolean    TRUE - соединение установлено, FALSE - не установлено
  */
 protected function _connMemcached()
 {
     if (!empty($this->memcached)) {
         return TRUE;
     }
     if (class_exists('Memcached')) {
         $this->memcached = new Memcached();
         if (count($GLOBALS['memcachedServers']) == 1) {
             if ($this->memcached->addServer($GLOBALS['memcachedServers'][0], 11211)) {
                 return TRUE;
             }
         } else {
             if (count($GLOBALS['memcachedServers']) > 1) {
                 if ($this->memcached->addServers($GLOBALS['memcachedServers'])) {
                     return FALSE;
                 }
             }
         }
     }
     return FALSE;
 }