本文整理汇总了PHP中Memcached::resetServerList方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcached::resetServerList方法的具体用法?PHP Memcached::resetServerList怎么用?PHP Memcached::resetServerList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcached
的用法示例。
在下文中一共展示了Memcached::resetServerList方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getConnection
/**
* Create the Memcached connection
*
* @return void
*
* @since 12.1
* @throws RuntimeException
*/
protected function getConnection()
{
if (!static::isSupported()) {
throw new RuntimeException('Memcached Extension is not available');
}
$config = JFactory::getConfig();
$host = $config->get('memcached_server_host', 'localhost');
$port = $config->get('memcached_server_port', 11211);
// Create the memcached connection
if ($config->get('memcached_persist', true)) {
static::$_db = new Memcached($this->_hash);
$servers = static::$_db->getServerList();
if ($servers && ($servers[0]['host'] != $host || $servers[0]['port'] != $port)) {
static::$_db->resetServerList();
$servers = array();
}
if (!$servers) {
static::$_db->addServer($host, $port);
}
} else {
static::$_db = new Memcached();
static::$_db->addServer($host, $port);
}
static::$_db->setOption(Memcached::OPT_COMPRESSION, $this->_compress);
$stats = static::$_db->getStats();
$result = !empty($stats["{$host}:{$port}"]) && $stats["{$host}:{$port}"]['pid'] > 0;
if (!$result) {
// Null out the connection to inform the constructor it will need to attempt to connect if this class is instantiated again
static::$_db = null;
throw new JCacheExceptionConnecting('Could not connect to memcached server');
}
}
示例2: __destruct
public function __destruct()
{
if ($this->instance) {
$this->instance->resetServerList();
unset($this->instance);
}
}
示例3: setMemcached
/**
* @param \Memcached|null $memcached
*/
public function setMemcached($memcached = null)
{
if ($memcached) {
$this->memcached = $memcached;
}
if ($this->memcached) {
$this->memcached->resetServerList();
$this->memcached->addServer($this->server, $this->port);
}
}
示例4: maybeAddServerConnections
/**
* Maybe add server connections.
*
* @since 151216 Memcached utilities.
*/
protected function maybeAddServerConnections()
{
if (!$this->Pool) {
return;
// Not possible.
}
if ($this->serversDiffer()) {
$this->Pool->quit();
$this->Pool->resetServerList();
$this->Pool->addServers($this->servers);
}
}
示例5: testDelete
public function testDelete()
{
$this->storage->get('oldkey');
$this->assertArrayHasKey('oldkey', $this->storage->getCasArray(), 'Cas array has not key "oldkey"!');
$this->assertEquals(0, $this->storage->delete('oldkey'), 'Delete failed!');
$this->assertArrayNotHasKey('oldkey', $this->storage->getCasArray(), 'Cas array has key "oldkey"!');
try {
self::$memcached->resetServerList();
$this->storage->delete('oldkey');
} catch (StorageException $e) {
if (count(self::$memcached->getServerList()) == 0) {
self::$memcached->addServers(array(array(MEMCACHED_HOST, MEMCACHED_PORT)));
}
return;
}
$this->fail('Storage delete exception test failed');
}
示例6: getStats
public function getStats()
{
$stats = $this->handler->getStats();
$servers = $this->servers;
foreach ($stats as $key => $stat) {
if ($stat['pid'] === -1) {
//移除不可用的server
unset($servers[$key]);
}
}
//没有可用的server
if (empty($servers)) {
$this->isConnected = false;
return false;
} else {
$this->handler->resetServerList();
$status = $this->handler->addServers(array_values($servers));
if ($status) {
$this->isConnected = true;
}
return $status;
}
}
示例7: Memcached
<?php
$mem = new Memcached();
$mem->addServer("localhost", 1234);
var_dump(count($mem->getServerList()));
$mem->resetServerList();
var_dump($mem->getServerList());