本文整理汇总了PHP中Memcache类的典型用法代码示例。如果您正苦于以下问题:PHP Memcache类的具体用法?PHP Memcache怎么用?PHP Memcache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Memcache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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');
}
}
示例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;
}
}
示例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);
}
}
}
}
}
}
示例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();
}
}
示例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;
}
}
示例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');
}
示例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);
}
示例9: get_cache
function get_cache($key)
{
//获取缓存
$m = new Memcache();
$m->connect(Cache_IP, Cache_Port);
return $m->get($key);
}
示例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;
}
示例11: testSetInstanceSuccess
public function testSetInstanceSuccess()
{
$driver = $this->getDriver();
$client = new \Memcache();
$client->addserver('localhost');
$driver->setInstance($client);
}
示例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;
}
示例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;
}
}
示例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;
}
示例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');
});
}