本文整理汇总了PHP中Memcached::addserver方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcached::addserver方法的具体用法?PHP Memcached::addserver怎么用?PHP Memcached::addserver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcached
的用法示例。
在下文中一共展示了Memcached::addserver方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Construct the adapter, giving an array of servers.
* @example
* array(
* 'prefix' => '',
* 'persistent_id' => '',
* 'servers' => array(
* array (
* 'host' => 'cache1.example.com',
* 'port' => 11211,
* 'weight' => 1
* ),
* array(
* 'host' => 'cache2.example.com',
* 'port' => 11211,
* 'weight' => 2
* )
* )
* )
* @param array $config
*/
public function __construct(array $config = array())
{
try {
if (array_key_exists('prefix', $config)) {
$this->prefix = $config['prefix'];
}
if (array_key_exists('persistent_id', $config) && !empty($config['persistent_id'])) {
// @codeCoverageIgnoreStart
$this->memcached = new \Memcached($config['persistent_id']);
} else {
// @codeCoverageIgnoreEnd
$this->memcached = new \Memcached();
}
foreach ($config['servers'] as $server) {
$this->memcached->addserver($server['host'], $server['port'], $server['weight']);
}
if (array_key_exists('options', $config)) {
foreach ($config['options'] as $optionKey => $optionValue) {
$this->memcached->setOption($optionKey, $optionValue);
}
}
} catch (\Exception $e) {
// @codeCoverageIgnoreStart
$this->memcached = null;
// @codeCoverageIgnoreEnd
}
}
示例2: initializeObject
/**
* Initializes the identifier prefix
*
* @return void
* @throws Exception
*/
public function initializeObject()
{
if (empty($this->servers)) {
throw new Exception('No servers were given to Memcache', 1213115903);
}
$memcachedPlugin = '\\' . ucfirst($this->usedPeclModule);
$this->memcache = new $memcachedPlugin();
$defaultPort = $this->usedPeclModule === 'memcache' ? ini_get('memcache.default_port') : 11211;
foreach ($this->servers as $server) {
if (substr($server, 0, 7) === 'unix://') {
$host = $server;
$port = 0;
} else {
if (substr($server, 0, 6) === 'tcp://') {
$server = substr($server, 6);
}
if (strpos($server, ':') !== false) {
list($host, $port) = explode(':', $server, 2);
} else {
$host = $server;
$port = $defaultPort;
}
}
$this->memcache->addserver($host, $port);
}
if ($this->usedPeclModule === 'memcached') {
$this->memcache->setOption(\Memcached::OPT_COMPRESSION, $this->getCompression());
}
}
示例3: initialize
/**
* Sets up and returns the CacheProvider
* @param $config
* @return \Doctrine\Common\Cache\CacheProvider
*/
protected function initialize($config)
{
$memcached = new \Memcached();
$memcached->addserver($config['host'], $config['port']);
$cache = new MemcachedCache();
$cache->setMemcached($memcached);
return $cache;
}
示例4: __construct
/**
* Initializes usage of memcache or memcached
*/
private function __construct()
{
$ini = eZINI::instance('merck.ini');
if ( $ini->hasSection('MemcacheSettings') )
{
$this->_host = $ini->variable('MemcacheSettings', 'Host');
$this->_port = $ini->variable('MemcacheSettings', 'Port');
}
elseif( strpos(ini_get('session.save_handler'), 'memcache') === 0
&& preg_match('#^(?:tcp://)?(?P<memcacheHost>[^:]+):(?P<memcachePort>[^?]+)#', ini_get('session.save_path'), $m)
){
// No memcache settings set, we try to use the session handler one
$this->_host = $m['memcacheHost'];
$this->_port = $m['memcachePort'];
}
if ( $this->_host )
{
if ( extension_loaded('memcached') )
{
$this->_memcache = new Memcached();
$this->_type = self::TYPE_MEMCACHED;
$this->_isValid = $this->_memcache->addserver( $this->_host, $this->_port );
}
elseif( extension_loaded( 'memcache') )
{
$this->_memcache = new Memcache();
$this->_type = self::TYPE_MEMCACHE;
$this->_isValid = $this->_memcache->connect( $this->_host, $this->_port );
}
}
if ( !$this->isValid() )
{
eZDebug::writeError('Could not find any valid memcache configuration or memcache module', 'MemcacheTool');
// do not break. Any memcache w/r should be fault tolerant in case memcache clears its cache by itself.
}
}