本文整理汇总了PHP中Memcache::addserver方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcache::addserver方法的具体用法?PHP Memcache::addserver怎么用?PHP Memcache::addserver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcache
的用法示例。
在下文中一共展示了Memcache::addserver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(array $config = null)
{
$config = $config ?: \Kalibri::config()->get('cache');
$this->_memcache = new \Memcache();
foreach ($config['servers'] as $server) {
$this->_memcache->addserver($server['host'], $server['port'], true, isset($server['weight']) ? $server['weight'] : 1);
}
}
示例2: init
/**
* Initialize memcache
*
* @return \Magelight\Cache\Adapter\Memcached
*/
public function init()
{
$this->memcached = new \Memcache();
foreach ((array) $this->config->xpath('servers/server') as $server) {
$this->memcached->addserver((string) $server->host, (int) $server->port);
}
return $this;
}
示例3: __construct
public function __construct()
{
if (!class_exists('\\Memcache')) {
throw new \PHPUnit_Framework_SkippedTestError('Test cannot be ran, you need Memcache');
}
$this->cache = new \Memcache();
$this->cache->addserver("localhost");
}
示例4: __construct
/**
* Constructor
* @param array $options cache store storage option
*/
public function __construct($options = array())
{
$this->connect = new \Memcache();
$this->prefix = $options['prefix'];
$this->default_ttl = $options['default_ttl'];
$this->default_flag = isset($options['default_flag']) ? $options['default_flag'] : 0;
foreach ($options['servers'] as $server) {
$this->connect->addserver($server[0], $server[1]);
}
}
示例5: init
/**
* {@inheritDoc}
*/
public function init(array $connections)
{
if (!class_exists("\\Memcache")) {
throw new \Exception("'Memcache' class does not exist. Please install it to be able to use the Memcache connections");
}
$this->memcache = new \Memcache();
foreach ($connections as $connection) {
$this->memcache->addserver($connection["host"], $connection["port"]);
}
}
示例6: addServer
protected function addServer(array $server)
{
if (!array_key_exists('host', $server)) {
throw new \InvalidArgumentException('host key must be set');
}
$server['port'] = isset($server['port']) ? (int) $server['port'] : 11211;
$server['timeout'] = isset($server['timeout']) ? (int) $server['timeout'] : 1;
$server['persistent'] = isset($server['persistent']) ? (bool) $server['persistent'] : false;
$server['weight'] = isset($server['weight']) ? (int) $server['weight'] : 1;
$server['retry_interval'] = isset($server['retry_interval']) ? (int) $server['retry_interval'] : 15;
$this->memcache->addserver($server['host'], $server['port'], $server['persistent'], $server['weight'], $server['timeout'], $server['retry_interval']);
}
示例7: __construct
/**
* Construct the adapter, giving an array of servers.
* @example
* array(
* array(
* 'host' => 'cache1.example.com',
* 'port' => 11211,
* 'weight' => 1,
* 'timeout' => 60
* ),
* array(
* 'host' => 'cache2.example.com',
* 'port' => 11211,
* 'weight' => 2,
* 'timeout' => 60
* )
* )
* @param array $servers
*/
public function __construct(array $servers)
{
try {
$this->memcache = new \Memcache();
foreach ($servers as $server) {
$this->memcache->addserver($server['host'], $server['port'], null, $server['weight'], $server['timeout']);
}
} catch (\Exception $e) {
// @codeCoverageIgnoreStart
$this->memcache = null;
// @codeCoverageIgnoreEnd
}
}
示例8: __construct
/**
* @param $cache
* @param $period
* @param string $cachePrefix
* @throws \Exception
*/
public function __construct($cache, $period, $cachePrefix = 'informers')
{
$this->period = $period;
$this->cachePrefix = $cachePrefix;
if ($cache instanceof \Memcache) {
$this->cache = $cache;
} elseif (is_array($cache)) {
$this->cache = new \Memcache();
$this->cache->addserver($cache['host'], $cache['port']);
} else {
throw new ClientException('Incorrect cache configuration');
}
}
示例9: __construct
/**
* Construct the Memcache based cache provider
* @param array $objOptionsArray array of server options. Each item in the array contains an associative
* arrays with options for the server to add to memcache
*/
public function __construct($objOptionsArray)
{
$this->objMemcache = new Memcache();
foreach ($objOptionsArray as $objServerOptions) {
$host = $objServerOptions["host"];
$port = array_key_exists("port", $objServerOptions) ? $objServerOptions["port"] : 11211;
$persistent = array_key_exists("persistent", $objServerOptions) ? $objServerOptions["persistent"] : true;
$weight = array_key_exists("weight", $objServerOptions) ? $objServerOptions["weight"] : 10;
$timeout = array_key_exists("timeout", $objServerOptions) ? $objServerOptions["timeout"] : 1;
$retry_interval = array_key_exists("retry_interval", $objServerOptions) ? $objServerOptions["retry_interval"] : 15;
$status = array_key_exists("status", $objServerOptions) ? $objServerOptions["status"] : true;
$failure_callback = array_key_exists("failure_callback", $objServerOptions) ? $objServerOptions["failure_callback"] : null;
$this->objMemcache->addserver($host, $port, $persistent, $weight, $timeout, $retry_interval, $status, $failure_callback);
}
}
示例10: __construct
/**
* Конструктор кеша
*/
public function __construct()
{
//Проверяем ключи в конфиге
if (!isset(Boot::getInstance()->config->memcache->host) || !isset(Boot::getInstance()->config->memcache->port)) {
throw new Boot_Exception('Не указаны настройки Memcache', 500);
}
//Добавляем префикс
if (isset(Boot::getInstance()->config->memcache->prefix)) {
$this->prefix = Boot::getInstance()->config->memcache->prefix . "::";
}
//Инициализируем класс кеша
$this->m = new Memcache();
//Добавляем сервер
$this->m->addserver(Boot::getInstance()->config->memcache->host, Boot::getInstance()->config->memcache->port);
}
示例11: register
public function register(Application $app)
{
$app->setParameter('cache', ['namespace' => null, 'type' => 'array']);
$app->singleton('cache', function () use($app) {
$cache = null;
$type = $app->getParameter('cache.type', 'array');
if ($type == 'array') {
$cache = new ArrayCache();
} elseif ($type == 'apc') {
$cache = new ApcCache();
} elseif ($type == 'xcache') {
$cache = new XcacheCache();
} elseif ($type == 'memcache') {
$cache = new MemcacheCache();
$memcache = new \Memcache();
$memcache->addserver($app->getParameter('cache.memcached.host', '127.0.0.1'), $app->getParameter('cache.memcached.port', 11211));
$cache->setMemcache($memcache);
} elseif ($type == 'memcached') {
$cache = new MemcachedCache();
$memcached = new \Memcached();
$memcached->addServer($app->getParameter('cache.memcached.host', '127.0.0.1'), $app->getParameter('cache.memcached.port', 11211));
$cache->setMemcached($memcached);
}
$cache->setNamespace($app->getParameter('cache.namespace'));
return $cache;
});
}
示例12: 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());
}
}
示例13: initializeObject
/**
* Initializes the identifier prefix
*
* @return void
* @throws \TYPO3\CMS\Core\Cache\Exception
*/
public function initializeObject()
{
if (empty($this->servers)) {
throw new \TYPO3\CMS\Core\Cache\Exception('No servers were given to Memcache', 1213115903);
}
$this->memcache = new \Memcache();
$defaultPort = ini_get('memcache.default_port');
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);
}
}
示例14: testSetInstanceSuccess
public function testSetInstanceSuccess()
{
$driver = $this->getDriver();
$client = new \Memcache();
$client->addserver('localhost');
$driver->setInstance($client);
}
示例15: __construct
/**
* Construct the adapter, giving an array of servers.
* @example
* array(
* 'prefix' => '',
* 'servers' => array(
* array (
* 'host' => 'cache1.example.com',
* 'port' => 11211,
* 'weight' => 1,
* 'timeout' => 60
* ),
* array(
* 'host' => 'cache2.example.com',
* 'port' => 11211,
* 'weight' => 2,
* 'timeout' => 60
* )
* )
* )
* @param array $config
*/
public function __construct(array $config = array())
{
try {
if (array_key_exists('prefix', $config)) {
$this->prefix = $config['prefix'];
}
$this->memcache = new \Memcache();
foreach ($config['servers'] as $server) {
$this->memcache->addserver($server['host'], $server['port'], null, $server['weight'], $server['timeout']);
}
} catch (\Exception $e) {
// @codeCoverageIgnoreStart
$this->memcache = null;
// @codeCoverageIgnoreEnd
}
}