本文整理汇总了PHP中object::addServer方法的典型用法代码示例。如果您正苦于以下问题:PHP object::addServer方法的具体用法?PHP object::addServer怎么用?PHP object::addServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类object
的用法示例。
在下文中一共展示了object::addServer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Class constructor
*
* Setup Memcache(d)
*
* @return void
*/
public function __construct()
{
// Try to load memcached server info from the config file.
$defaults = $this->_memcacheConf['default'];
$config = Config::getSoul()->CACHE;
$memcacheConf = isset($config['MEMCACHED']) ? $config['MEMCACHED'] : null;
if (is_array($memcacheConf)) {
$this->_memcacheConf = array();
foreach ($memcacheConf as $name => $conf) {
$this->_memcacheConf[$name] = $conf;
}
}
if (class_exists('Memcached', false)) {
$this->_memcached = new \Memcached();
} elseif (class_exists('Memcache', false)) {
$this->_memcached = new \Memcache();
} else {
Log::normal('[Error] Failed to create Memcache(d) object; extension not loaded?');
}
foreach ($this->_memcacheConf as $cacheServer) {
isset($cacheServer['HOST']) or $cacheServer['HOST'] = $defaults['HOST'];
isset($cacheServer['PORT']) or $cacheServer['PORT'] = $defaults['PORT'];
isset($cacheServer['WEIGHT']) or $cacheServer['WEIGHT'] = $defaults['WEIGHT'];
if (get_class($this->_memcached) === 'Memcache') {
// Third parameter is persistance and defaults to TRUE.
$this->_memcached->addServer($cacheServer['HOST'], $cacheServer['PORT'], true, $cacheServer['WEIGHT']);
} else {
$this->_memcached->addServer($cacheServer['HOST'], $cacheServer['PORT'], $cacheServer['WEIGHT']);
}
}
Hook::listen(__CLASS__);
}
示例2: init
/**
* Initialize the Cache Engine
*
* Called automatically by the cache frontend
* To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
*
* @param array $setting array of setting for the engine
* @return boolean True if the engine has been successfully initialized, false if not
* @access public
*/
function init($settings = array())
{
if (!class_exists('Memcache')) {
return false;
}
parent::init(array_merge(array('engine' => 'Memcache', 'prefix' => Inflector::slug(APP_DIR) . '_', 'servers' => array('127.0.0.1'), 'compress' => false), $settings));
if ($this->settings['compress']) {
$this->settings['compress'] = MEMCACHE_COMPRESSED;
}
if (!is_array($this->settings['servers'])) {
$this->settings['servers'] = array($this->settings['servers']);
}
if (!isset($this->__Memcache)) {
$this->__Memcache =& new Memcache();
foreach ($this->settings['servers'] as $server) {
$parts = explode(':', $server);
$host = $parts[0];
$port = 11211;
if (isset($parts[1])) {
$port = $parts[1];
}
if ($this->__Memcache->addServer($host, $port)) {
return true;
}
}
return false;
}
return true;
}
示例3: foreach
/**
* Constructor of the container class.
*
* $options can have these keys:
* 'servers' an array containing an array: servername, port,
* sharedsecret, timeout, maxtries
* 'configfile' The filename of the configuration file
* 'authtype' The type of authentication, one of: PAP, CHAP_MD5,
* MSCHAPv1, MSCHAPv2, default is PAP
*
* @param $options associative array
* @return object Returns an error object if something went wrong
*/
function Auth_Container_RADIUS($options)
{
$this->authtype = 'PAP';
if (isset($options['authtype'])) {
$this->authtype = $options['authtype'];
}
$classname = 'Auth_RADIUS_' . $this->authtype;
if (!class_exists($classname)) {
PEAR::raiseError("Unknown Authtype, please use on of: PAP, CHAP_MD5, MSCHAPv1, MSCHAPv2!", 41, PEAR_ERROR_DIE);
}
$this->radius = new $classname();
if (isset($options['configfile'])) {
$this->radius->setConfigfile($options['configfile']);
}
$servers = $options['servers'];
if (is_array($servers)) {
foreach ($servers as $server) {
$servername = $server[0];
$port = isset($server[1]) ? $server[1] : 0;
$sharedsecret = isset($server[2]) ? $server[2] : 'testing123';
$timeout = isset($server[3]) ? $server[3] : 3;
$maxtries = isset($server[4]) ? $server[4] : 3;
$this->radius->addServer($servername, $port, $sharedsecret, $timeout, $maxtries);
}
}
if (!$this->radius->start()) {
PEAR::raiseError($this->radius->getError(), 41, PEAR_ERROR_DIE);
}
}
示例4: __construct
public function __construct($config = [])
{
parent::__construct(__NAMESPACE__, $config);
set_time_limit(0);
ini_set('memory_limit', '1024M');
$this->_Worker = new \GearmanWorker();
foreach ($this->_config['servers'] as $server) {
$this->_Worker->addServer($server['host'], $server['port']);
}
// учитывая, что addServer всегда возвращает true, делаем дополнительный ping сервера для проверки его реакции
if (!$this->_Worker->echo(self::WORKLOAD_TEST)) {
throw new Exception('Не удалось соединиться с сервером');
}
$this->_Db = new Db($this->_config['Db']);
// последний рестарт
$this->_started = $this->_Db->lastRestart();
if (!empty($this->_function)) {
if (is_string($this->_function)) {
$this->_Worker->addFunction($this->_function($this->_function), [$this, 'doJob']);
} elseif (is_array($this->_function)) {
foreach ($this->_function as $name => $callback) {
$this->_Worker->addFunction($this->_function($name), is_array($callback) ? $callback : [$this, $callback]);
}
}
}
$this->_Worker->addFunction("restart_{$this->_started}", [$this, 'halt']);
}
示例5: init
/**
* Initialize the Cache Engine
*
* Called automatically by the cache frontend
* To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
*
* @param array $setting array of setting for the engine
* @return boolean True if the engine has been successfully initialized, false if not
* @access public
*/
function init($settings = array())
{
if (!class_exists('Memcache')) {
return false;
}
parent::init($settings);
$defaults = array('servers' => array('127.0.0.1'), 'compress' => false);
$this->settings = array_merge($this->settings, $defaults, $settings);
if ($this->settings['compress']) {
$this->settings['compress'] = MEMCACHE_COMPRESSED;
}
if (!is_array($this->settings['servers'])) {
$this->settings['servers'] = array($this->settings['servers']);
}
$this->__Memcache =& new Memcache();
foreach ($this->settings['servers'] as $server) {
$parts = explode(':', $server);
$host = $parts[0];
$port = 11211;
if (isset($parts[1])) {
$port = $parts[1];
}
if ($this->__Memcache->addServer($host, $port)) {
return true;
}
}
return false;
}
示例6: _connect
/**
* Подключение к серверу
*
* @param bool $reconnect пепеподключение, если нужно
* @throws Exception
* @return bool
*/
protected function _connect($reconnect = true)
{
// уже подключены
if (!$reconnect && $this->_connected) {
return $this->_connected;
}
// убиваем старое соедение
unset($this->_Client);
$this->_connected = false;
// ну и всё заново
$this->_Client = new \GearmanClient();
$server = !empty($this->_config['servers']) && empty($this->_config['server']) ? $this->_config['servers'][0] : $this->_config['server'];
$this->_Client->addServer($server['host'], $server['port']);
// учитывая, что addServer всегда возвращает true, делаем дополнительный ping сервера для проверки его реакции
if (!$this->_Client->ping(self::WORKLOAD_TEST)) {
throw new Exception('Не удалось соединиться с сервером');
}
$this->_connected = true;
if (is_callable([$this, 'done'])) {
if (!$this->_Client->setCompleteCallback([$this, 'done'])) {
throw new Exception('Не удалось установить обработчик');
}
}
if (is_callable([$this, 'exception'])) {
if (!$this->_Client->setExceptionCallback([$this, 'exception'])) {
throw new Exception('Не удалось установить обработчик исключений');
}
}
return $this->_connected;
}
示例7: __construct
/**
* Constructor
*
* @param array $options Options
*/
public function __construct(array $options)
{
parent::__construct($options);
$this->client = new GearmanClient();
foreach ($this->_config['servers'] as $server) {
$this->client->addServer($server);
}
}
示例8: connect
/**
* 连接服务器
*
* @return boolean
*/
public function connect()
{
$this->oCache = new Memcache();
foreach ($this->aConf as $host) {
$this->oCache->addServer($host['host'], $host['port']);
}
$this->oCache->setCompressThreshold(10000, 0.2);
return true;
}
示例9: __construct
/**
* We open up a connection to each of the memcached servers.
*
*/
public function __construct()
{
$this->_oDb = new Memcache();
$aHosts = Phpfox::getParam('core.memcache_hosts');
$bPersistent = Phpfox::getParam('core.memcache_persistent');
foreach ($aHosts as $aHost) {
$this->_oDb->addServer($aHost['host'], $aHost['port'], $bPersistent);
}
}
示例10: init
/**
* Start the session.
*
* @return mixed NULL if no errors, however FALSE if session cannot start.
*/
public function init()
{
session_set_save_handler(array($this, 'open'), array($this, 'close'), array($this, 'read'), array($this, 'write'), array($this, 'destroy'), array($this, 'gc'));
$this->_oDb = new Memcache();
$aHosts = Phpfox::getParam('core.memcache_hosts');
$bPersistent = Phpfox::getParam('core.memcache_persistent');
foreach ($aHosts as $aHost) {
$this->_oDb->addServer($aHost['host'], $aHost['port'], $bPersistent);
}
if (!isset($_SESSION)) {
session_start();
}
}
示例11: __construct
/**
* Constructor
* @since Version 3.8.7
* @return void
*/
public function __construct()
{
if (!defined("DS")) {
define("DS", DIRECTORY_SEPARATOR);
}
$path = dirname(dirname(__DIR__)) . DS . "config" . DS . "config.railpage.json";
if (file_exists($path)) {
$Config = json_decode(file_get_contents($path));
$this->host = $Config->Memcached->Host;
$this->port = $Config->Memcached->Port;
$this->cn = new PHPMemcached();
$this->cn->addServer($this->host, $this->port);
}
}
示例12: __construct
public function __construct($driver, \Liten\Liten $liten = null)
{
$this->app = !empty($liten) ? $liten : \Liten\Liten::getInstance();
if ($driver == 'file') {
$this->_cache = new \app\src\Core\Cache\etsis_Cache_Filesystem();
} elseif ($driver == 'apc') {
$this->_cache = new \app\src\Core\Cache\etsis_Cache_APC();
} elseif ($driver == 'memcache') {
/**
* Filter whether to use `\Memcache`|`\Memcached`.
*
* @since 6.2.0
* @param
* bool false Use `\Memcache`|`\Memcached`. Default is false.
*/
$useMemcached = $this->app->hook->apply_filter('use_memcached', false);
$this->_cache = new \app\src\Core\Cache\etsis_Cache_Memcache($useMemcached);
$pool = [['host' => '127.0.0.1', 'port' => 11211, 'weight' => 20]];
/**
* Filter the `\Memcache`|`\Memcached` server pool.
*
* @since 6.2.0
* @param array $pool
* Array of servers to add to the connection pool.
*/
$servers = $this->app->hook->apply_filter('memcache_server_pool', $pool);
$this->_cache->addServer($servers);
} elseif ($driver == 'external') {
/**
* Fires when being used to call another caching system not
* native to eduTrac SIS.
*
* @since 6.2.0
*/
$this->_cache = $this->app->hook->do_action('external_cache_driver');
} elseif ($driver == 'xcache') {
$this->_cache = new \app\src\Core\Cache\etsis_Cache_XCache();
} elseif ($driver == 'cookie') {
$this->_cache = new \app\src\Core\Cache\etsis_Cache_Cookie();
} elseif ($driver == 'json') {
$this->_cache = new \app\src\Core\Cache\etsis_Cache_JSON();
} elseif ($driver == 'memory') {
$this->_cache = new \app\src\Core\Cache\etsis_Cache_Memory();
}
if (is_etsis_exception($this->_cache)) {
return $this->_cache->getMessage();
}
return $this->_cache;
}
示例13: __construct
/**
* Class constructor
* 构造函数 类构造器
* Setup Memcache(d)
* 设置Memcache
* @return void
*/
public function __construct()
{
// Try to load memcached server info from the config file. 试图加载memcached服务器配置文件的信息。
$CI =& get_instance();
$defaults = $this->_memcache_conf['default'];
if ($CI->config->load('memcached', TRUE, TRUE)) {
if (is_array($CI->config->config['memcached'])) {
$this->_memcache_conf = array();
foreach ($CI->config->config['memcached'] as $name => $conf) {
$this->_memcache_conf[$name] = $conf;
}
}
}
if (class_exists('Memcached', FALSE)) {
$this->_memcached = new Memcached();
} elseif (class_exists('Memcache', FALSE)) {
$this->_memcached = new Memcache();
} else {
log_message('error', 'Cache: Failed to create Memcache(d) object未能创建Memcache(d)对象; extension not loaded?扩展不加载?');
}
foreach ($this->_memcache_conf as $cache_server) {
isset($cache_server['hostname']) or $cache_server['hostname'] = $defaults['host'];
isset($cache_server['port']) or $cache_server['port'] = $defaults['port'];
isset($cache_server['weight']) or $cache_server['weight'] = $defaults['weight'];
if (get_class($this->_memcached) === 'Memcache') {
// Third parameter is persistance and defaults to TRUE. 第三个参数是持久性和默认值为TRUE。
$this->_memcached->addServer($cache_server['hostname'], $cache_server['port'], TRUE, $cache_server['weight']);
} else {
$this->_memcached->addServer($cache_server['hostname'], $cache_server['port'], $cache_server['weight']);
}
}
}
示例14: __construct
/**
* Class constructor
*
* Setup Memcache(d)
*
* @return void
*/
public function __construct()
{
// Try to load memcached server info from the config file.
$defaults = $this->_config['default'];
$this->_config = Config::get('cache')->memcached;
if (class_exists('Memcached', FALSE)) {
$this->_memcached = new Memcached();
} elseif (class_exists('Memcache', FALSE)) {
$this->_memcached = new Memcache();
} else {
Logger::logError('Cache: Failed to create Memcache(d) object; extension not loaded?');
return;
}
foreach ($this->_config as $cache_server) {
isset($cache_server['hostname']) or $cache_server['hostname'] = $defaults['host'];
isset($cache_server['port']) or $cache_server['port'] = $defaults['port'];
isset($cache_server['weight']) or $cache_server['weight'] = $defaults['weight'];
if ($this->_memcached instanceof Memcache) {
// Third parameter is persistance and defaults to TRUE.
$this->_memcached->addServer($cache_server['hostname'], $cache_server['port'], TRUE, $cache_server['weight']);
} elseif ($this->_memcached instanceof Memcached) {
$this->_memcached->addServer($cache_server['hostname'], $cache_server['port'], $cache_server['weight']);
}
}
}
示例15: initMemcached
/**
* Inits memcached server if it needed
*
* @return void
*/
protected function initMemcached()
{
if ($this->storage == 'memcached') {
$this->memcached = new Memcached();
$this->memcached->addServer($this->memcachedServer, $this->memcachedPort);
}
}