public function load($group_name = 'default') { $obj_couchbase_name = 'MYCOUCHBASE' . $group_name; if ($this->{$obj_couchbase_name}) { return $this->{$obj_couchbase_name}; } $cfg = $this->cfg[$group_name]; $this->CI->load->library('monitor'); $random = FALSE; if (is_array($cfg) === FALSE) { log_message('error', 'The Memcached config is not array'); exit; } $this->CI->load->library('monitor'); $random = FALSE; if ($cfg['cfg']['random'] == TRUE) { $random = TRUE; } if ($random === TRUE) { $this->CI->load->helper('random'); $fail = array(); getCouchbase: $rnd = randomExcept(0, count($cfg['data']) - 1, $fail); if (is_numeric($rnd)) { if ($this->CI->monitor->check_status('COUCHBASE', array('position' => $rnd, 'group' => $group_name)) === true) { $couchbase_position = $rnd; } else { $fail[] = $rnd; goto getCouchbase; } } } else { for ($i = 0, $c = count($cfg['data']); $i < $c; $i++) { if ($this->CI->monitor->check_status('COUCHBASE', array('position' => $i, 'group' => $group_name)) === true) { $couchbase_position = $i; break; } } } if ($cfg['data'][$couchbase_position]) { $cbcfg = $cfg['data'][$couchbase_position]; $status = TRUE; } else { $status = FALSE; } if (is_array($cbcfg)) { $cb = new Couchbase($cbcfg['ip'], $cbcfg['username'], $cbcfg['password'], $cbcfg['db_name']); if ($cb->getResultCode() != COUCHBASE_SUCCESS) { $this->CI->monitor->increment_fail('COUCHBASE', array('position' => $couchbase_position, 'group' => $group_name)); $cb = new CouchBaseInterface(); } $this->{$obj_couchbase_name} = $cb; } else { $cb = new CouchBaseInterface(); } return $cb; }
public function load($cache_type, $group_name, $options = array()) { $cfg_cache = $this->cfg_cache[$cache_type][$group_name]; if (empty($cfg_cache) == TRUE) { return false; } switch ($cache_type) { case 'file': $obj_cache_name = 'MY' . $cache_type . $group_name; $this->CI->load->driver('cache', array('adapter' => 'file', 'params' => array('obj' => $obj_cache_name, 'path' => $cfg_cache['path'])), $obj_cache_name); return $this->CI->{$obj_cache_name}; break; case 'memcache': if (is_array($cfg_cache) === FALSE) { log_message('error', 'The Memcached config is not array'); exit; } $this->CI->load->library('monitor'); $random = FALSE; if ($cfg_cache['cfg']['random'] == TRUE) { $random = TRUE; } if ($random === TRUE) { $this->CI->load->helper('random'); $fail = array(); getMemcache: $rnd = randomExcept(0, count($cfg_cache['data']) - 1, $fail); if (is_numeric($rnd)) { if ($this->CI->monitor->check_status('MEMCACHE', array('position' => $rnd, 'group' => $group_name)) === true) { $cache_position = $rnd; } else { $fail[] = $rnd; goto getMemcache; } } } else { for ($i = 0, $c = count($cfg_cache['data']); $i < $c; $i++) { if ($this->CI->monitor->check_status('MEMCACHE', array('position' => $i, 'group' => $group_name)) === true) { $cache_position = $i; break; } } } if ($cfg_cache['data'][$cache_position]) { $memcfg['host'] = $cfg_cache['data'][$cache_position]['host']; $memcfg['port'] = $cfg_cache['data'][$cache_position]['port']; $status = TRUE; } else { $status = FALSE; } $obj_cache_name = 'MY' . $cache_type . $group_name; $this->CI->load->driver('cache', array('adapter' => 'memcached', 'params' => array('obj' => $obj_cache_name, 'hostname' => $memcfg['host'], 'port' => $memcfg['port'], 'status' => $status)), $obj_cache_name); if ($this->CI->{$obj_cache_name}->check() === FALSE) { $this->CI->monitor->increment_fail('MEMCACHE', array('position' => $cache_position, 'group' => '')); } unset($memcfg); return $this->CI->{$obj_cache_name}; break; default: break; } }