当前位置: 首页>>代码示例>>PHP>>正文


PHP Memcache::setServerParams方法代码示例

本文整理汇总了PHP中Memcache::setServerParams方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcache::setServerParams方法的具体用法?PHP Memcache::setServerParams怎么用?PHP Memcache::setServerParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Memcache的用法示例。


在下文中一共展示了Memcache::setServerParams方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  *
  * @throws Exception
  */
 protected function __construct()
 {
     if (!class_exists('Memcache', false)) {
         throw new Exception('Class Memcache not Found. php5-memcache may not be installed.');
     }
     self::$_Connection = new Memcache();
     foreach (self::$_MemCachePool as $_host => $weight) {
         list($host, $port) = explode(":", $_host);
         self::$_Connection->addServer($host, $port, true, $weight);
     }
     $results = @self::$_Connection->getExtendedStats();
     foreach ($results as $__host => $_stats) {
         if (empty($_stats)) {
             list($host, $port) = explode(":", $__host);
             self::$_Connection->setServerParams($host, $port, 1, -1, false);
             Log::doLog("Server {$host}:{$port} down, not available.");
             unset(self::$_MemCachePool[$__host]);
         }
     }
     if (empty(self::$_MemCachePool)) {
         throw new Exception('No Memcached servers available. All down.');
     }
     register_shutdown_function('MemcacheHandler::close');
 }
开发者ID:indynagpal,项目名称:MateCat,代码行数:28,代码来源:MemcacheHandler.php

示例2: foreach

 /**
  * Callback method for Memcache::failure_callback to use if any Memcache call
  * on a particular server fails. This method switches off that instance of the
  * server if the configuration setting `instant_death` is set to `TRUE`.
  *
  * @param   string   hostname 
  * @param   integer  port 
  * @return  void|boolean
  * @since   3.0.8
  */
 function _failed_request($hostname, $port)
 {
     if (!$this->conf['instant_death']) {
         return;
     }
     // Setup non-existent host
     $host = FALSE;
     // Get host settings from configuration
     foreach ($this->conf['servers'] as $server) {
         if ($hostname == $server['host'] and $port == $server['port']) {
             $host = $server;
             continue;
         }
     }
     if (!$host) {
         return;
     } else {
         return $this->memcache->setServerParams($host['host'], $host['port'], $host['timeout'], $host['retry_interval'], FALSE, array($this, '_failed_request'));
     }
 }
开发者ID:googlecode-mirror,项目名称:f-engine,代码行数:30,代码来源:memcache.php

示例3: _failed_request

 /**
  * Callback method for Memcache::failure_callback to use if any Memcache call
  * on a particular server fails. This method switches off that instance of the
  * server if the configuration setting `instant_death` is set to `TRUE`.
  * @param   string $hostname
  * @param   integer $port
  * @return  void|boolean
  * @since   3.0.8
  */
 public function _failed_request($hostname, $port)
 {
     if (!$this->_config['instant_death']) {
         return;
     }
     // Setup non-existent host
     $host = false;
     // Get host settings from configuration
     foreach ($this->_config['servers'] as $server) {
         // Merge the defaults, since they won't always be set
         $server += $this->_default_config;
         // We're looking at the failed server
         if ($hostname == $server['host'] and $port == $server['port']) {
             // Server to disable, since it failed
             $host = $server;
             continue;
         }
     }
     if (!$host) {
         return;
     } else {
         return $this->_memcache->setServerParams($host['host'], $host['port'], $host['timeout'], $host['retry_interval'], false, [$this, '_failed_request']);
     }
 }
开发者ID:astar3086,项目名称:studio_logistic,代码行数:33,代码来源:Memcache.php

示例4: registerMemcacheHandler

 protected function registerMemcacheHandler(Application $app)
 {
     $app['session.handler_factory.backing_memcache'] = $app->protect(function ($connections) {
         $memcache = new \Memcache();
         foreach ($connections as $conn) {
             $args = [$conn['host'] ?: 'localhost', $conn['port'] ?: 11211, $conn['persistent'] ?: false];
             if ($conn['weight'] > 0) {
                 $args[] = $conn['weight'];
                 if ($conn['timeout'] > 1) {
                     $args[] = $conn['timeout'];
                 }
             }
             call_user_func_array([$memcache, 'addServer'], $args);
             if ($conn['weight'] <= 0 && $conn['timeout'] > 1) {
                 $memcache->setServerParams($args[0], $args[1], $conn['timeout']);
             }
         }
         return $memcache;
     });
     $app['session.handler_factory.backing_memcached'] = $app->protect(function ($connections) {
         $memcache = new \Memcached();
         foreach ($connections as $conn) {
             $memcache->addServer($conn['host'] ?: 'localhost', $conn['port'] ?: 11211, $conn['weight'] ?: 0);
         }
         return $memcache;
     });
     $app['session.handler_factory.memcache'] = $app->protect(function ($options, $key = 'memcache') use($app) {
         $connections = $this->parseConnections($options, 'localhost', 11211);
         $memcache = $app['session.handler_factory.backing_' . $key]($connections);
         $handlerOptions = [];
         if (isset($options['expiretime'])) {
             $handlerOptions['expiretime'] = $options['expiretime'];
         }
         if (isset($options['prefix'])) {
             $handlerOptions['prefix'] = $options['prefix'];
         }
         if ($key === 'memcache') {
             return new MemcacheHandler($memcache, $handlerOptions);
         } else {
             return new MemcachedHandler($memcache, $handlerOptions);
         }
     });
     $app['session.handler_factory.memcached'] = $app->protect(function ($options) use($app) {
         return $app['session.handler_factory.memcache']($options, 'memcached');
     });
 }
开发者ID:bolt,项目名称:bolt,代码行数:46,代码来源:SessionServiceProvider.php

示例5: foreach

 $memcache_save_path = '';
 #addServer foreach $memcache_settings['servers']
 foreach ($memcache_settings['servers'] as $server) {
     #bool Memcache::addServer ( string $host [, int $port = 11211 [, bool $persistent [, int $weight [, int $timeout [, int $retry_interval [, bool $status [, callback $failure_callback [, int $timeoutms ]]]]]]]] ) ### from php.net
     if ($_GET['debug']) {
         echo "\n", '$memcache->addServer : ', var_export($server, true), "\n";
     }
     $addServer_status = NULL;
     $memcache_host = $server['host'];
     $memcache_port = $server['port'];
     if ($using_MemcachePool) {
         $addServer_status = $memcache->addServer($server['host'], $server['port'], $server['udp_port'], $server['persistent'], $server['timeout'], $server['retry_interval']);
         if (array_key_exists('status', $server) && !$server['status']) {
             $server['retry_interval'] = -1;
             #it does not make sense to have any other value for retry_interval if status is false
             if (!$memcache->setServerParams($server['host'], $server['port'], $server['timeout'], $server['retry_interval'], $server['status']) && $_GET['debug']) {
                 echo "\nFailed to set {$memcache_host} status to offline\n";
             } else {
                 if ($_GET['debug']) {
                     echo "\nSet {$memcache_host} status to offline\n";
                 }
             }
         }
     } else {
         $addServer_status = $memcache->addServer($server['host'], $server['port'], $server['persistent'], $server['weight'], $server['timeout'], $server['retry_interval'], $server['status'], $server['callback_failure']);
     }
     if ($_GET['debug']) {
         if ($addServer_status) {
             echo "\nSuccessfully added {$memcache_host}\n";
         } else {
             echo "\nFailed to add {$memcache_host}\n";
开发者ID:HotwireCommunications,项目名称:skyphp,代码行数:31,代码来源:mem-connect.php


注:本文中的Memcache::setServerParams方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。