• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Memcache类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: AuthMemCookie_getMemCache

function AuthMemCookie_getMemCache()
{
    static $memcache;
    /* Return now if we already have a Memcache object. */
    if ($memcache) {
        return $memcache;
    }
    $memcache = new Memcache();
    /* In the config we store memcache servers as a string of host:port-pairs
     * separated by ','. The port number is optional if the server runs at the
     * default port (11211).
     * Example: 'localhost:23122,remote1,10.0.0.71:43232'
     */
    $servers = AuthMemCookie_getOption('memcache_servers', '127.0.0.1');
    foreach (explode(',', $servers) as $server) {
        $hostport = explode(':', $server);
        $host = $hostport[0];
        $port = (int) $hostport[1];
        if (!$port) {
            $port = 11211;
        }
        /* Add server to pool. Sets a weight of 1 and a 10-second timeout. */
        $memcache->addServer($host, $port, TRUE, 1, 10);
    }
    return $memcache;
}
开发者ID:GajendraNaidu,项目名称:openam,代码行数:26,代码来源:authmemcookie.php


示例2: setUp

	/**
	 * Sets up the fixture, for example, opens a network connection.
	 * This method is called before a test is executed.
	 *
	 * @return void
	 * @access protected
	 */
	protected function setUp()
	{
		$memcachetest = false;
		include_once JPATH_BASE.'/libraries/joomla/cache/storage.php';
		include_once JPATH_BASE.'/libraries/joomla/cache/storage/memcache.php';

		if((extension_loaded('memcache') && class_exists('Memcache')) != true ) {
			$this->memcacheAvailable = false; } else {

			$config = JFactory::getConfig();
			$host = $config->get('memcache_server_host', 'localhost');
			$port = $config->get('memcache_server_port',11211);

			$memcache = new Memcache;
			$memcachetest = @$memcache->connect($host, $port); }

			 if (!$memcachetest)
			 {
			 		$this->memcacheAvailable = false;
			 } else $this->memcacheAvailable = true;


		if ($this->memcacheAvailable)
		{
			$this->object = JCacheStorage::getInstance('memcache');
		}
	}
开发者ID:realityking,项目名称:JAJAX,代码行数:34,代码来源:JCacheStorageMemcacheTest.php


示例3: connect

 protected function connect()
 {
     if (class_exists("Memcache")) {
         if (function_exists("getMemcached")) {
             if ($vc6b2148720c14fb58871f480a7cc042e = getmemcached()) {
                 $this->memcache = $vc6b2148720c14fb58871f480a7cc042e;
                 $this->connected = true;
                 return true;
             }
         }
         $vc6b2148720c14fb58871f480a7cc042e = new Memcache();
         $v3a8e4c06e471595f6eb262bb9b5582d9 = mainConfiguration::getInstance();
         $v67b3dba8bc6778101892eb77249db32e = $v3a8e4c06e471595f6eb262bb9b5582d9->get('cache', 'memcache.host');
         if (empty($v67b3dba8bc6778101892eb77249db32e)) {
             $v67b3dba8bc6778101892eb77249db32e = 'localhost';
         }
         $v901555fb06e346cb065ceb9808dcfc25 = $v3a8e4c06e471595f6eb262bb9b5582d9->get('cache', 'memcache.port');
         if (is_null($v901555fb06e346cb065ceb9808dcfc25)) {
             $v901555fb06e346cb065ceb9808dcfc25 = '11211';
         }
         if ($vc6b2148720c14fb58871f480a7cc042e->connect($v67b3dba8bc6778101892eb77249db32e, $v901555fb06e346cb065ceb9808dcfc25)) {
             $this->memcache = $vc6b2148720c14fb58871f480a7cc042e;
             $this->connected = true;
             return true;
         }
         return false;
     } else {
         return false;
     }
 }
开发者ID:BGCX261,项目名称:zimmerli-svn-to-git,代码行数:30,代码来源:memcache.php


示例4: __construct

 public function __construct($exp = 3600)
 {
     $this->expire = $exp;
     if (defined('CACHE_DRIVER')) {
         $this->cachedriver = CACHE_DRIVER;
     }
     if ($this->cachedriver == 'memcached') {
         $mc = new Memcache();
         if ($mc->pconnect(MEMCACHE_HOSTNAME, MEMCACHE_PORT)) {
             $this->memcache = $mc;
             $this->ismemcache = true;
         }
     }
     if (!$this->ismemcache) {
         $files = glob(DIR_CACHE . 'cache.*');
         if ($files) {
             foreach ($files as $file) {
                 $time = substr(strrchr($file, '.'), 1);
                 if ($time < time()) {
                     if (file_exists($file)) {
                         @touch($file);
                         @unlink($file);
                     }
                 }
             }
         }
     }
 }
开发者ID:rb2,项目名称:ocstoreru,代码行数:28,代码来源:cache.php


示例5: defaultAction

 public function defaultAction()
 {
     $memcache = new Memcache();
     $memcache->flush();
     $usuario = new Usuario();
     $daoUsuario = DAOFactory::getUsuarioDAO();
     /** @var $user User */
     $user = UserService::getCurrentUser();
     if (isset($user)) {
         $usuarioBD = $daoUsuario->queryByGoogle($user->getUserId());
         if (!$usuarioBD) {
             // No existe el usuario
             $usuario->google = $user->getUserId();
             $usuario->correo = $user->getEmail();
             $usuario->nombre = $user->getNickname();
             $daoUsuario->insert($usuario);
         } else {
             $usuario = $usuarioBD;
         }
         $_SESSION['logoutUrl'] = UserService::createLogoutUrl('/index/closeSession');
         $_SESSION['usuario'] = $usuario;
         include 'vod/index.php';
     } else {
         $this->login();
     }
 }
开发者ID:roberto-pina,项目名称:ventana-educativa,代码行数:26,代码来源:IndexController.class.php


示例6: indexAction

 public function indexAction()
 {
     $entries = new Entry();
     // test memcached
     if (extension_loaded('memcache')) {
         $mem = new Memcache();
         $mem->addServer('localhost', 11211);
         $result = $mem->get('indexContent');
         if (!$result) {
             $result = $entries->fetchLatest(100);
             $mem->set('indexContent', $result, 0, 4);
         }
     } else {
         $result = $entries->fetchLatest(100);
     }
     if ($result) {
         $this->view->entries = $result;
         // Zend_Paginator
         $page = $this->_request->getParam('page', 1);
         $paginator = Zend_Paginator::factory($result);
         $paginator->setItemCountPerPage(4);
         $paginator->setCurrentPageNumber($page);
         $this->view->paginator = $paginator;
     }
 }
开发者ID:kalimatas,项目名称:zbook,代码行数:25,代码来源:IndexController.php


示例7: Run

 public function Run()
 {
     $memcache = new \Memcache();
     $this->AssertEquals($memcache->connect('localhost', 11211), TRUE, 'connect');
     $memcache->set('testkey', 'testvalue', MEMCACHE_COMPRESSED);
     $this->AssertEquals($memcache->get('testkey'), 'testvalue');
 }
开发者ID:JasonOcean,项目名称:iOS_Interest_Group,代码行数:7,代码来源:memcache_ut.php


示例8: DeleteAll

 /**
  * Invalidate all the objects in the cache
  * @return void
  */
 public function DeleteAll()
 {
     $this->objMemcache->flush();
     // needs to wait one second after flush.
     //  See comment on http://www.php.net/manual/ru/memcache.flush.php#81420
     sleep(1);
 }
开发者ID:vaibhav-kaushal,项目名称:qc-framework,代码行数:11,代码来源:QCacheProviderMemcache.class.php


示例9: get_cache

function get_cache($key)
{
    //获取缓存
    $m = new Memcache();
    $m->connect(Cache_IP, Cache_Port);
    return $m->get($key);
}
开发者ID:Moearly,项目名称:myshop,代码行数:7,代码来源:functions.php


示例10: getStatsFromCache

function getStatsFromCache($type = 'sizes', $slabib = null, $limit = 100)
{
    $ini = parse_ini_file('scielo.def', true);
    $memcache = new Memcache();
    $memcache->connect($ini['CACHE']['SERVER_CACHE'], $ini['CACHE']['SERVER_PORT_CACHE']);
    if ($slabib != null) {
        $arr = $memcache->getExtendedStats($type, $slabid, $limit);
    } else {
        $arr = $memcache->getExtendedStats($type);
    }
    $saida = '';
    $arr = array_pop($arr);
    $saida .= '<table border="1">';
    foreach ($arr as $key => $value) {
        $saida .= '<tr>';
        $saida .= '<td>' . $key . '</td>';
        if (is_array($value)) {
            $saida .= '<td><table border="1">';
            foreach ($value as $k => $v) {
                $saida .= '<tr>';
                $saida .= '<td>' . $k . '</td>';
                $saida .= '<td>' . $v . '</td>';
                $saida .= '</tr>';
            }
            $saida .= '</table></td>';
        } else {
            $saida .= '<td>' . $value . '</td>';
        }
        $saida .= '</tr>';
    }
    $saida .= '</table>';
    $memcache->close();
    return $saida;
}
开发者ID:robertatakenaka,项目名称:Proceedings,代码行数:34,代码来源:cache.php


示例11: testSetInstanceSuccess

 public function testSetInstanceSuccess()
 {
     $driver = $this->getDriver();
     $client = new \Memcache();
     $client->addserver('localhost');
     $driver->setInstance($client);
 }
开发者ID:noikiy,项目名称:owl,代码行数:7,代码来源:MemcacheTest.php


示例12: init

 public function init()
 {
     $bootstrapOptions = $this->getBootstrap()->getOptions();
     $options = $this->getOptions();
     $memcache = null;
     $doctrineConfig = new \Doctrine\ORM\Configuration();
     if (!empty($options['options']['metadataCache'])) {
         $metaCache = new $options['options']['metadataCache']();
         if ($metaCache instanceof \Doctrine\Common\Cache\MemcacheCache) {
             $memcache = new Memcache();
             $memcache->connect('localhost', 11211);
             $metaCache->setMemcache($memcache);
         }
         $doctrineConfig->setMetadataCacheImpl($metaCache);
     }
     if (!empty($options['options']['queryCache'])) {
         $queryCache = new $options['options']['queryCache']();
         if ($queryCache instanceof \Doctrine\Common\Cache\MemcacheCache) {
             if (is_null($memcache)) {
                 $memcache = new Memcache();
                 $memcache->connect('localhost', 11211);
             }
             $queryCache->setMemcache($memcache);
         }
         $doctrineConfig->setQueryCacheImpl($queryCache);
     }
     $driverImpl = $doctrineConfig->newDefaultAnnotationDriver(array($options['paths']['entities']));
     $doctrineConfig->setMetadataDriverImpl($driverImpl);
     //$doctrineConfig->setEntityNamespaces(
     //    $options['entitiesNamespaces']);
     $doctrineConfig->setProxyDir($options['paths']['proxies']);
     $doctrineConfig->setProxyNamespace($options['options']['proxiesNamespace']);
     $this->getBootstrap()->em = \Doctrine\ORM\EntityManager::create($options['connections']['doctrine'], $doctrineConfig);
     return $this->getBootstrap()->em;
 }
开发者ID:rehoutm,项目名称:Zend_Db-vs.-Doctrine-2,代码行数:35,代码来源:Doctrine2.php


示例13: getCacheProvider

 /**
  * @return  CacheProvider
  */
 protected function getCacheProvider()
 {
     $config = $this->getConfig()->get('orm.cache');
     switch ($config['provider']) {
         case 'array':
             return new ArrayCache();
         case 'filesystem':
             return new FilesystemCache($config[$config['provider']]['directory'], $config[$config['provider']]['extension']);
         case 'redis':
             $redis = new \Redis();
             $redis->connect($config[$config['provider']]['host'], $config[$config['provider']]['port']);
             $redis->select($config[$config['provider']]['dbindex']);
             $cache = new RedisCache();
             $cache->setRedis($redis);
             return $cache;
         case 'memcached':
             $memcache = new \Memcache();
             $memcache->connect($config[$config['provider']]['host'], $config[$config['provider']]['port'], $config[$config['provider']]['weight']);
             $cache = new MemcacheCache();
             $cache->setMemcache($memcache);
             return $cache;
         default:
             return null;
     }
 }
开发者ID:ntd1712,项目名称:common,代码行数:28,代码来源:EntityManagerFactory.php


示例14: elggcache_cacheinit

function elggcache_cacheinit()
{
    global $CFG, $messages;
    //memcache_debug(true);
    if (!empty($CFG->elggcache_enabled)) {
        static $memcacheconn;
        //var_dump($memcacheconn);
        if (!isset($memcacheconn)) {
            if (!empty($CFG->elggcache_debug)) {
                $messages[] = 'connecting to memcache<br />';
            }
            $memcacheconn = new Memcache();
            $memcacheconn->pconnect($CFG->elggcache_memcache_host, $CFG->elggcache_memcache_port);
        }
        //var_dump($memcacheconn);
        if (empty($memcacheconn) || !is_resource($memcacheconn->connection)) {
            $CFG->elggcache_enabled = false;
            if (!empty($CFG->elggcache_debug)) {
                $messages[] = 'failed connect to memcache<br />';
            }
        }
    } else {
        $memcacheconn = false;
    }
    //$stats = $memcacheconn->getExtendedStats();
    //var_dump($stats);
    //var_dump($memcacheconn);
    return $memcacheconn;
}
开发者ID:BackupTheBerlios,项目名称:tulipan-svn,代码行数:29,代码来源:engine.memcache.php


示例15: register

 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->package('opensolutions/doctrine2bridge', 'doctrine2bridge');
     $this->app['config']->package('opensolutions/doctrine2bridge', __DIR__ . '/../config');
     $this->app->singleton('d2cachebridge', function ($app) {
         $cacheClass = "\\Doctrine\\Common\\Cache\\" . \Config::get('doctrine2bridge::cache.type');
         if (!class_exists($cacheClass)) {
             throw new Exception\ImplementationNotFound($cacheClass);
         }
         $cache = new $cacheClass();
         if (\Config::has('doctrine2bridge::cache.namespace')) {
             $cache->setNamespace(\Config::get('doctrine2bridge::cache.namespace'));
         }
         switch (\Config::get('doctrine2bridge::cache.type')) {
             case 'MemcacheCache':
                 $memcache = new \Memcache();
                 if (!\Config::has('doctrine2bridge::cache.memcache.servers') || !count(\Config::get('doctrine2bridge::cache.memcache.servers'))) {
                     throw new Exception\Configuration('No servers defined for Doctrine2Bridge\\Doctrine2CacheBridgeServiceProvider - Memcache');
                 }
                 foreach (\Config::get('doctrine2bridge::cache.memcache.servers') as $server) {
                     $memcache->addServer($server['host'], isset($server['port']) ? $server['port'] : 11211, isset($server['persistent']) ? $server['persistent'] : false, isset($server['weight']) ? $server['weight'] : 1, isset($server['timeout']) ? $server['timeout'] : 1, isset($server['retry_int']) ? $server['retry_int'] : 15);
                     $cache->setMemcache($memcache);
                 }
                 break;
         }
         return $cache;
     });
     // Shortcut so developers don't need to add an Alias in app/config/app.php
     \App::booting(function () {
         $loader = \Illuminate\Foundation\AliasLoader::getInstance();
         $loader->alias('D2Cache', 'Doctrine2Bridge\\Support\\Facades\\Doctrine2Cache');
     });
 }
开发者ID:opensolutions,项目名称:doctrine2bridge,代码行数:38,代码来源:Doctrine2CacheBridgeServiceProvider.php


示例16: getMemcacheKeys

function getMemcacheKeys()
{
    $memcache = new Memcache();
    $memcache->connect('127.0.0.1', 11211) or die("Could not connect to memcache server");
    $list = array();
    $allSlabs = $memcache->getExtendedStats('slabs');
    $items = $memcache->getExtendedStats('items');
    foreach ($allSlabs as $server => $slabs) {
        foreach ($slabs as $slabId => $slabMeta) {
            if (!is_numeric($slabId)) {
                continue;
            }
            $cdump = $memcache->getExtendedStats('cachedump', (int) $slabId);
            asort($cdump);
            foreach ($cdump as $keys => $arrVal) {
                if (!is_array($arrVal)) {
                    continue;
                }
                foreach ($arrVal as $k => $v) {
                    if (!$_GET['key'] || strpos($k, $_GET['key']) !== false) {
                        print "<tr><td>" . date('H:i:s d.m.Y', $v[1] + 108955) . "</td><td><a href='?key=" . $k . "'>" . $k . "</a></td><td>" . ($v[1] - time()) . "</td></tr>\n";
                    }
                }
            }
        }
    }
}
开发者ID:staticweb,项目名称:webfilter,代码行数:27,代码来源:mem.php


示例17: factory

 public static function factory(Configuration $conf)
 {
     switch (strtolower($conf['session-server']['type'])) {
         case 'memcache':
             $memcache = new \Memcache();
             if (!@$memcache->connect($conf['session-server']['host'], $conf['session-server']['port'])) {
                 throw new RuntimeException(sprintf('Unable to connect to memcache server at %s:%s', $conf['session-server']['host'], $conf['session-server']['port']));
             }
             return new MemcacheSessionHandler($memcache);
             break;
         case 'memcached':
             $memcached = new \Memcached();
             if (!@$memcached->addServer($conf['session-server']['host'], $conf['session-server']['port'])) {
                 throw new RuntimeException(sprintf('Unable to connect to memcached server at %s:%s', $conf['session-server']['host'], $conf['session-server']['port']));
             }
             $memcached->getVersion();
             if (\Memcached::RES_SUCCESS !== $memcached->getResultCode()) {
                 throw new RuntimeException(sprintf('Unable to connect to memcached server at %s:%s', $conf['session-server']['host'], $conf['session-server']['port']));
             }
             return new MemcachedSessionHandler($memcached);
             break;
         case 'mongo':
         case 'pdo':
             throw new RuntimeException(sprintf('Session handler %s is not yet supported', $conf['session-server']['type']));
             break;
         default:
             throw new RuntimeException(sprintf('Session handler %s is not a valid type', $conf['session-server']['type']));
             break;
     }
 }
开发者ID:gloubster,项目名称:server,代码行数:30,代码来源:SessionHandler.php


示例18: factory

 /**
  * Singleton method
  * @static
  * @param string $type
  * @return Zend_Cache
  */
 public static function factory($type = 'File', $options = array())
 {
     if (!self::$cache_object) {
         $front_opt = array('automatic_serialization' => true);
         if (self::$life_time) {
             $front_opt['lifeTime'] = self::$life_time;
         }
         switch ($type) {
             case 'Memcached':
                 $mhost = $options['memcache_host'];
                 $mport = $options['memcache_port'];
                 $memcache = new Memcache();
                 if (!@$memcache->connect($mhost, $mport)) {
                     require_once 'Hush/Cache/Exception.php';
                     throw new Hush_Cache_Exception('Can not connect to memcache server');
                 }
                 $back_opt = array('servers' => array('host' => $mhost, 'port' => $mport));
                 break;
             default:
                 if (!is_dir($options['cache_dir'])) {
                     if (realpath(__DAT_DIR)) {
                         mkdir(realpath(__DAT_DIR) . '/cache', 0600);
                         $options['cache_dir'] = realpath(__DAT_DIR . '/cache');
                     } else {
                         require_once 'Hush/Cache/Exception.php';
                         throw new Hush_Cache_Exception('Can not found cache_dir file directory');
                     }
                 }
                 $back_opt = array('cache_dir' => $options['cache_dir']);
                 break;
         }
         self::$cache_object = Zend_Cache::factory('Core', $type, $front_opt, $back_opt);
     }
     return self::$cache_object;
 }
开发者ID:LWFeng,项目名称:hush,代码行数:41,代码来源:Cache.php


示例19: initMemCache

function initMemCache()
{
    global $memcache;
    $memcache = new Memcache();
    $memcache->connect('localhost', 11211) or die('Could not connect');
    //    memcache_flush($memcache);
}
开发者ID:technotronic12,项目名称:WixBis,代码行数:7,代码来源:Utils.php


示例20: 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;
     });
 }
开发者ID:itlessons,项目名称:php-application,代码行数:27,代码来源:DoctrineCacheProvider.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Memcached类代码示例发布时间:2022-05-23
下一篇:
PHP Members类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap