class MemcacheConnection in Memcache API and Integration 8.2
Class MemcacheConnection.
Hierarchy
- class \Drupal\memcache\Connection\MemcacheConnection implements MemcacheConnectionInterface
Expanded class hierarchy of MemcacheConnection
1 file declares its use of MemcacheConnection
- MemcacheDriverFactory.php in src/
Driver/ MemcacheDriverFactory.php
File
- src/
Connection/ MemcacheConnection.php, line 8
Namespace
Drupal\memcache\ConnectionView source
class MemcacheConnection implements MemcacheConnectionInterface {
/**
* The memcache object.
*
* @var \Memcache
*/
protected $memcache;
/**
* Constructs a MemcacheConnection object.
*/
public function __construct() {
$this->memcache = new \Memcache();
}
/**
* {@inheritdoc}
*/
public function addServer($server_path, $persistent = FALSE) {
list($host, $port) = explode(':', $server_path);
// Support unix sockets in the format 'unix:///path/to/socket'.
if ($host == 'unix') {
// When using unix sockets with Memcache use the full path for $host.
$host = $server_path;
// Port is always 0 for unix sockets.
$port = 0;
}
// When using the PECL memcache extension, we must use ->(p)connect
// for the first connection.
return $this
->connect($host, $port, $persistent);
}
/**
* {@inheritdoc}
*/
public function getMemcache() {
return $this->memcache;
}
/**
* {@inheritdoc}
*/
public function close() {
$this->memcache
->close();
}
/**
* Connects to a memcache server.
*
* @param string $host
* The server path without port.
* @param int $port
* The server port.
* @param bool $persistent
* Whether this server connection is persistent or not.
*
* @return \Memcache|bool
* A Memcache object for a successful persistent connection. TRUE for a
* successful non-persistent connection. FALSE when the server fails to
* connect.
*/
protected function connect($host, $port, $persistent) {
if ($persistent) {
return @$this->memcache
->pconnect($host, $port);
}
else {
return @$this->memcache
->connect($host, $port);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MemcacheConnection:: |
protected | property | The memcache object. | |
MemcacheConnection:: |
public | function |
Adds a memcache server. Overrides MemcacheConnectionInterface:: |
|
MemcacheConnection:: |
public | function |
Closes the memcache instance connection. Overrides MemcacheConnectionInterface:: |
|
MemcacheConnection:: |
protected | function | Connects to a memcache server. | |
MemcacheConnection:: |
public | function |
Returns the internal memcache object. Overrides MemcacheConnectionInterface:: |
|
MemcacheConnection:: |
public | function | Constructs a MemcacheConnection object. |