本文整理汇总了PHP中resource::addServer方法的典型用法代码示例。如果您正苦于以下问题:PHP resource::addServer方法的具体用法?PHP resource::addServer怎么用?PHP resource::addServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类resource
的用法示例。
在下文中一共展示了resource::addServer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
/**
* 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');
}
示例2: open
/**
* 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;
}
示例3: __construct
/**
* 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);
}
}
示例4: exit
/**
* 构造函数
*
* @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']));
}
}
}
示例5: Memcached
/**
* 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();
}
}
示例6: _connMemcached
/**
* Устанавливает соединение с сервером 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;
}