本文整理汇总了PHP中Memcache::pconnect方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcache::pconnect方法的具体用法?PHP Memcache::pconnect怎么用?PHP Memcache::pconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcache
的用法示例。
在下文中一共展示了Memcache::pconnect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Class constructor
*
* @param $memcache_host, $memcache_port
*/
public function __construct($memcache_host = '127.0.0.1', $memcache_port = 11211)
{
if (is_null($this->memcache) || !is_object($this->memcache)) {
$this->memcache = new Memcache();
if (!$this->memcache->pconnect($memcache_host, $memcache_port)) {
throw new Exception("Error in object initialization", 2);
}
}
}
示例2: open
/**
* Open up the backend
*
* @param string $savePath
* @param string $sessionName
* @return boolean
*/
public function open($savePath, $sessionName)
{
$this->_backend = new Memcache();
// Open a persistent or regular connection
if ($this->_config['persistent']) {
$this->_backend->pconnect($this->_config['hostname'], $this->_config['port'], $this->_config['timeout_connect']);
} else {
$this->_backend->connect($this->_config['hostname'], $this->_config['port'], $this->_config['timeout_connect']);
}
}
示例3: __construct
public function __construct($config)
{
$this->handler = new Memcache();
if (isset($config['keep-alive']) && $config['keep-alive']) {
$fd = $this->handler->pconnect($config['host'], $config['port'], TXConst::minute);
} else {
$fd = $this->handler->connect($config['host'], $config['port']);
}
if (!$fd) {
throw new TXException(4004, array($config['host'], $config['port']));
}
}
示例4: __construct
public function __construct($host = self::DEFAULT_HOST, $port = self::DEFAULT_PORT)
{
$this->instance = new \Memcache();
try {
try {
$this->instance->pconnect($host, $port);
} catch (BaseException $e) {
$this->instance->connect($host, $port);
}
$this->alive = true;
} catch (BaseException $e) {
// bad luck.
}
}
示例5: __construct
/**
* Конструктор
*
* @param array $servers
* @param boolean $persistent
*/
public function __construct($host, $port, $persistent = false)
{
if (!extension_loaded('memcache') || !class_exists('Memcache')) {
throw new _Core_Cache_Exception('Extension "memcache" is not loaded or not up to date !');
}
$this->server = new Memcache();
if ($persistent) {
$connected = $this->server->pconnect($host, $port);
} else {
$connected = $this->server->connect($host, $port);
}
if (!$connected) {
throw new _Core_Cache_Exception('Could not connect to memcached server on ' . $host . ':' . $port . ' !');
}
}
示例6: __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);
}
}
}
}
}
}
示例7: _on_initialize
/**
* This handler completes the configuration.
*/
public function _on_initialize()
{
if (array_key_exists('host', $this->_config)) {
$this->_host = $this->_config['host'];
}
if (array_key_exists('port', $this->_config)) {
$this->_port = $this->_config['port'];
}
// memcache does serialization automatically. no need for manual serialization
$this->_auto_serialize = false;
// Open the persistant connection.
if (is_null(self::$memcache)) {
self::$memcache = new Memcache();
try {
self::$memcache_operational = @self::$memcache->pconnect($this->_host, $this->_port);
} catch (Exception $e) {
// Memcache connection failed
if ($this->_abort_on_fail) {
debug_add("Failed to connect to {$this->_host}:{$this->_port}. " . $e->getMessage(), MIDCOM_LOG_ERROR);
// Abort the request
throw new midcom_error("Failed to connect to {$this->_host}:{$this->_port}.");
}
// Otherwise we just skip caching
debug_add("memcache handler: Failed to connect to {$this->_host}:{$this->_port}. " . $e->getMessage() . ". Serving this request without cache.", MIDCOM_LOG_ERROR);
self::$memcache_operational = false;
}
}
}
示例8: Memcache
function _init_connection()
{
if (!class_exists('Memcache')) {
return false;
}
$memcache_connection = new Memcache();
$server_list = explode(',', AMP_SYSTEM_MEMCACHE_SERVER);
$primary_server = array_shift($server_list);
$result = $memcache_connection->pconnect($primary_server, AMP_SYSTEM_MEMCACHE_PORT);
if (count($server_list)) {
foreach ($server_list as $additional_server) {
$result = $memcache_connection->addServer($additional_server, AMP_SYSTEM_MEMCACHE_PORT) || $result;
}
}
if ($result) {
$this->set_connection($memcache_connection);
} else {
trigger_error(sprintf(AMP_TEXT_ERROR_CACHE_REQUEST_FAILED, 'Memcache', 'connect', 'Request: ' . $_SERVER['REQUEST_URI']));
$result = $this->_restart_memcached();
//try again
if ($result) {
$this->set_connection($memcache_connection);
}
}
return $result;
}
示例9: 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;
}
示例10: __construct
public function __construct()
{
$host = '127.0.0.1';
$port = 11211;
$memcache = new \Memcache();
$memcache->pconnect($host, $port);
$this->memcache = $memcache;
}
示例11: __construct
/**
* {@inheritDoc}
*/
public function __construct($name)
{
$this->prefix = $name;
if (!self::$memcache) {
self::$memcache = new Memcache();
$host = Config::get('cache_host');
$port = Config::get('cache_port');
if (Config::get('cache_memcache_pconnect')) {
if (!@self::$memcache->pconnect($host, $port)) {
throw new CacheException("Couldn't connect to memcache server");
}
} else {
if (!@self::$memcache->connect($host, $port)) {
throw new CacheException("Couldn't connect to memcache server");
}
}
}
}
示例12: isAvailable
/**
* Detect if backend is available
* @return bool
*/
public static function isAvailable()
{
if (!extension_loaded('memcache')) {
return false;
}
if (self::$memcache) {
return true;
}
$serverList = [['unix:///tmp/memcache', 0], ['127.0.0.1', 11211]];
self::$memcache = new \MemCache();
foreach ($serverList as $serv) {
if (@self::$memcache->pconnect($serv[0], $serv[1])) {
self::$server = $serv[0];
self::$port = $serv[1];
return true;
}
}
return false;
}
示例13: enableMemcache
public function enableMemcache()
{
$this->memcacheConfig = ConfigManager::getConfig("Db", "Memcache")->AuxConfig;
if ($this->memcacheConfig->enabled) {
$memcache = new Memcache();
if ($memcache->pconnect($this->memcacheConfig->host, $this->memcacheConfig->port)) {
Minify::setCache(new Minify_Cache_Memcache($memcache));
}
}
}
示例14: getConnection
/**
* Create the Memcache connection
*
* @return void
*
* @since 11.1
* @throws RuntimeException
*/
protected function getConnection()
{
if (!static::isSupported()) {
throw new RuntimeException('Memcache Extension is not available');
}
$config = JFactory::getConfig();
$host = $config->get('memcache_server_host', 'localhost');
$port = $config->get('memcache_server_port', 11211);
// Create the memcache connection
static::$_db = new Memcache();
if ($config->get('memcache_persist', true)) {
$result = @static::$_db->pconnect($host, $port);
} else {
$result = @static::$_db->connect($host, $port);
}
if (!$result) {
// Null out the connection to inform the constructor it will need to attempt to connect if this class is instantiated again
static::$_db = null;
throw new JCacheExceptionConnecting('Could not connect to memcache server');
}
}
示例15: cache_memcache
function cache_memcache()
{
global $_W;
static $memcacheobj;
if (!extension_loaded('memcache')) {
return error(1, 'Class Memcache is not found');
}
if (empty($memcacheobj)) {
$config = $_W['config']['setting']['memcache'];
$memcacheobj = new Memcache();
if ($config['pconnect']) {
$connect = $memcacheobj->pconnect($config['server'], $config['port']);
} else {
$connect = $memcacheobj->connect($config['server'], $config['port']);
}
}
return $memcacheobj;
}