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


PHP Memcached::connect方法代码示例

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


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

示例1: Memcache

 /**
  * constructor of the handler - initialises Memcached object
  *
  * @return bool
  * 
  */
 function __construct()
 {
     #this ensures to write down and close the session when destroying the handler object
     register_shutdown_function("session_write_close");
     $this->memcache = new Memcache();
     $this->memcache->connect('MEMCACHE_NODE_ADDRESS_HERE', 11211);
     $this->lifeTime = intval(ini_get("session.cookie_lifetime"));
     $this->initSessionData = null;
     return true;
 }
开发者ID:royalwang,项目名称:php-session-memdb,代码行数:16,代码来源:class.session.php

示例2: _before

 public function _before(TestCase $test)
 {
     if (class_exists('\\Memcache')) {
         $this->memcache = new \Memcache();
         $this->memcache->connect($this->config['host'], $this->config['port']);
     } elseif (class_exists('\\Memcached')) {
         $this->memcache = new \Memcached();
         $this->memcache->addServer($this->config['host'], $this->config['port']);
     } else {
         throw new ModuleConfigException(__CLASS__, 'Memcache classes not loaded');
     }
 }
开发者ID:Marfuz,项目名称:c4t_test,代码行数:12,代码来源:Memcache.php

示例3: connect

 /**
  * Connect to the cache server(s).
  *
  * @throws CacheException
  * @access private
  */
 private function connect()
 {
     $this->connected = false;
     switch (NN_CACHE_TYPE) {
         case self::TYPE_REDIS:
             if ($this->socketFile === false) {
                 $servers = unserialize(NN_CACHE_HOSTS);
                 foreach ($servers as $server) {
                     if ($this->server->connect($server['host'], $server['port'], (double) NN_CACHE_TIMEOUT) === false) {
                         throw new CacheException('Error connecting to the Redis server!');
                     } else {
                         $this->connected = true;
                     }
                 }
             } else {
                 if ($this->server->connect(NN_CACHE_SOCKET_FILE) === false) {
                     throw new CacheException('Error connecting to the Redis server!');
                 } else {
                     $this->connected = true;
                 }
             }
             break;
         case self::TYPE_MEMCACHED:
             $params = $this->socketFile === false ? unserialize(NN_CACHE_HOSTS) : [[NN_CACHE_SOCKET_FILE, 'port' => 0]];
             if ($this->server->addServers($params) === false) {
                 throw new CacheException('Error connecting to the Memcached server!');
             } else {
                 $this->connected = true;
             }
             break;
         case self::TYPE_APC:
             $this->connected = true;
             break;
     }
 }
开发者ID:RickDB,项目名称:newznab-tmux,代码行数:41,代码来源:Cache.php

示例4: make

 public function make($config = null)
 {
     if (!extension_loaded('memcached')) {
         throw new \RuntimeException('Memcached extension was not loaded.');
     }
     $memcached = new \Memcached();
     $memcached->connect($config['host'], $config['port']);
     $cache = new MemcachedCache();
     $cache->setMemcached($memcached);
     return $cache;
 }
开发者ID:uedehua,项目名称:laravel5-doctrine,代码行数:11,代码来源:MemcachedProvider.php

示例5: __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.
        }
    }
开发者ID:sushilbshinde,项目名称:ezpublish-study,代码行数:41,代码来源:memcacheTool.php

示例6: memcacheSetup

 public static function memcacheSetup()
 {
     // Memcache provider setup:
     if (MEMCACHE_LIBRARY == 'memcache') {
         $memcache = new \Memcache();
     } else {
         if (MEMCACHE_LIBRARY == 'memcached') {
             $memcache = new \Memcached();
         }
     }
     if (!$memcache->connect(MEMCACHE_HOST, MEMCACHE_PORT)) {
         throw new exception('Unable to connect to Memcache');
     }
     return $memcache;
 }
开发者ID:mrjamescollins,项目名称:phang,代码行数:15,代码来源:Base.php

示例7: connect

 /**
  * Connect to the cache server(s).
  *
  * @throws CacheException
  * @access private
  */
 private function connect()
 {
     $this->connected = false;
     if ($this->isRedis === true) {
         if ($this->socketFile === false) {
             $servers = unserialize(nZEDb_CACHE_HOSTS);
             foreach ($servers as $server) {
                 if ($this->server->connect($server['host'], $server['port'], (double) nZEDb_CACHE_TIMEOUT) === false) {
                     throw new CacheException('Error connecting to the Redis server!');
                 } else {
                     $this->connected = true;
                 }
             }
         } else {
             if ($this->server->connect(nZEDb_CACHE_SOCKET_FILE) === false) {
                 throw new CacheException('Error connecting to the Redis server!');
             } else {
                 $this->connected = true;
             }
         }
     } else {
         if ($this->socketFile === false) {
             if ($this->server->addServers(unserialize(nZEDb_CACHE_HOSTS)) === false) {
                 throw new CacheException('Error connecting to the Memcached server!');
             } else {
                 $this->connected = true;
             }
         } else {
             if ($this->server->addServers(array(array(nZEDb_CACHE_SOCKET_FILE, 'port' => 0))) === false) {
                 throw new CacheException('Error connecting to the Memcached server!');
             } else {
                 $this->connected = true;
             }
         }
     }
 }
开发者ID:sebst3r,项目名称:nZEDb,代码行数:42,代码来源:Cache.php

示例8: import_vars

 public function import_vars($key = false)
 {
     if (Xcrud_config::$alt_session) {
         if (class_exists('Memcache')) {
             $mc = new Memcache();
             $mc->connect(Xcrud_config::$mc_host, Xcrud_config::$mc_port);
             $data = $mc->get($this->sess_id);
         } elseif (class_exists('Memcached')) {
             $mc = new Memcached();
             $mc->connect(Xcrud_config::$mc_host, Xcrud_config::$mc_port);
             $data = $mc->get($this->sess_id);
         } else {
             self::error('Can\'t use alternative session. Memcache(d) is not available');
         }
         if (!$data) {
             self::error('Can\'t use alternative session. Data is not exist');
         }
         $_SESSION['xcrud_session'] = $this->decrypt($data[0], $data[1]);
         unset($data);
         if (!$_SESSION['xcrud_session']) {
             self::error('Can\'t use alternative session. Data is invalid');
         }
     }
     $inst_name = $this->instance_name;
     foreach ($this->params2save() as $item) {
         $this->{$item} = $_SESSION['xcrud_session'][$inst_name][$item];
     }
     if ($key) {
         $this->key = $key;
     }
 }
开发者ID:jccarrizo,项目名称:git-hub-proyect,代码行数:31,代码来源:xcrud.php

示例9: connect

 /**
  * Connects to a server.
  *
  * @param string $hostname The hostname to connect to
  * @param string $port     The port to connect to
  *
  * @author Benjamin Carl <opensource@clickalicious.de>
  * @return Memcached The created instance of memcache
  * @access protected
  * @throws Doozr_Cache_Service_Exception
  */
 protected function connect($hostname, $port)
 {
     $memcache = new Memcached();
     // API requires to add server first
     $memcache->addServer($hostname, $port);
     // Finally we try to connect
     try {
         @$memcache->connect($hostname, $port);
     } catch (Exception $e) {
         throw new Doozr_Cache_Service_Exception(sprintf('Error while connecting to host: "%s" on Port: "%s". Connection failed.', $hostname, $port));
     }
     // return instance on success
     return $memcache;
 }
开发者ID:clickalicious,项目名称:doozr,代码行数:25,代码来源:Memcached.php

示例10: getCacheDriver

 /**
  * Automatically picks the cache mechanism to use.  If you pick one manually it will use that
  * If there is no config option for $driver in the config, or it's set to 'auto', it will
  * pick the best option based on which cache extensions are installed.
  *
  * @return DoctrineCache\CacheProvider  The cache driver to use
  */
 public function getCacheDriver()
 {
     $setting = $this->driver_setting;
     $driver_name = 'file';
     if (!$setting || $setting == 'auto') {
         if (extension_loaded('apcu')) {
             $driver_name = 'apcu';
         } elseif (extension_loaded('apc')) {
             $driver_name = 'apc';
         } elseif (extension_loaded('wincache')) {
             $driver_name = 'wincache';
         } elseif (extension_loaded('xcache')) {
             $driver_name = 'xcache';
         }
     } else {
         $driver_name = $setting;
     }
     $this->driver_name = $driver_name;
     switch ($driver_name) {
         case 'apc':
             $driver = new DoctrineCache\ApcCache();
             break;
         case 'apcu':
             $driver = new DoctrineCache\ApcuCache();
             break;
         case 'wincache':
             $driver = new DoctrineCache\WinCacheCache();
             break;
         case 'xcache':
             $driver = new DoctrineCache\XcacheCache();
             break;
         case 'memcache':
             $memcache = new \Memcache();
             $memcache->connect($this->config->get('system.cache.memcache.server', 'localhost'), $this->config->get('system.cache.memcache.port', 11211));
             $driver = new DoctrineCache\MemcacheCache();
             $driver->setMemcache($memcache);
             break;
         case 'memcached':
             $memcached = new \Memcached();
             $memcached->connect($this->config->get('system.cache.memcached.server', 'localhost'), $this->config->get('system.cache.memcached.port', 11211));
             $driver = new DoctrineCache\MemcachedCache();
             $driver->setMemcached($memcached);
             break;
         case 'redis':
             $redis = new \Redis();
             $redis->connect($this->config->get('system.cache.redis.server', 'localhost'), $this->config->get('system.cache.redis.port', 6379));
             $driver = new DoctrineCache\RedisCache();
             $driver->setRedis($redis);
             break;
         default:
             $driver = new DoctrineCache\FilesystemCache($this->cache_dir);
             break;
     }
     return $driver;
 }
开发者ID:dweelie,项目名称:grav,代码行数:62,代码来源:Cache.php

示例11: connect

 public function connect()
 {
     $conf = $this->conf;
     if ($this->link) {
         return $this->link;
     }
     if (extension_loaded('Memcache')) {
         $memcache = new Memcache();
     } elseif (extension_loaded('Memcached')) {
         $memcache = new Memcached();
     } else {
         $this->error(2, 'Memcache 扩展不存在。');
         return FALSE;
     }
     $r = $memcache->connect($conf['host'], $conf['port']);
     if (!$r) {
         $this->error(3, '连接 Memcached 服务器失败。');
         return FALSE;
     }
     $this->link = $memcache;
     return $this->link;
 }
开发者ID:xianyuxmu,项目名称:alinkagarden-xiuno,代码行数:22,代码来源:cache.class.php

示例12: Memcache

$modx->tpl = DLTemplate::getInstance($modx);
$modx->fs = \Helpers\FS::getInstance();
switch (true) {
    case function_exists('apc_cache_info'):
        $modx->cache = new \Doctrine\Common\Cache\ApcCache();
        break;
    case class_exists('Memcache'):
        $modx->cache = new \Doctrine\Common\Cache\MemcacheCache();
        $memcache = new Memcache();
        $memcache->connect('localhost', 11211);
        $modx->cache->setMemcache($memcache);
        break;
    case class_exists('Memcached'):
        $modx->cache = new \Doctrine\Common\Cache\MemcachedCache();
        $memcached = new Memcached();
        $memcached->connect('localhost', 11211);
        $modx->cache->setMemcache($memcached);
        break;
    case class_exists('SQLite3'):
        $modx->cache = new \Doctrine\Common\Cache\SQLite3Cache(new SQLite3(MODX_BASE_PATH . 'assets/cache/sqlite.db'), 'cache');
        break;
    default:
        $modx->cache = new Doctrine\Common\Cache\FilesystemCache(MODX_BASE_PATH . 'assets/cache/template/');
}
$modx->cache->setNamespace($modx->getConfig('site_name'));
$moduleDebug = false;
if (!is_ajax() && ($modx->isFrontend() && $modx->getLoginUserID('mgr')) || $modx->isBackend() && isset($_GET['a']) && $_GET['a'] == 112 && $moduleDebug) {
    error_reporting(E_ALL);
    ini_set('display_errors', true);
}
if ($modx->isFrontend() && $modx->getLoginUserID('web') && $modx->user instanceof \modUsers) {
开发者ID:russelgal,项目名称:EvoTwig,代码行数:31,代码来源:__autoload.php

示例13: Memcached

<?php

//
// apt-get install php5-memcache
//
$memcache_enabled = extension_loaded("memcached");
if ($memcache_enabled) {
    echo "extension loaded";
} else {
    echo "extension not loaded";
}
$mc = new Memcached();
$mc->connect("localhost", 11211);
print_r($mc->getStats());
开发者ID:RickDB,项目名称:newznab-tmux,代码行数:14,代码来源:memcache.php


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