3 namespace Drupal\memcache\Connection;
6 * Class MemcacheConnection.
8 class MemcacheConnection implements MemcacheConnectionInterface {
11 * The memcache object.
18 * Constructs a MemcacheConnection object.
20 public function __construct() {
21 $this->memcache = new \Memcache();
27 public function addServer($server_path, $persistent = FALSE) {
28 list($host, $port) = explode(':', $server_path);
30 // Support unix sockets in the format 'unix:///path/to/socket'.
31 if ($host == 'unix') {
32 // When using unix sockets with Memcache use the full path for $host.
34 // Port is always 0 for unix sockets.
38 // When using the PECL memcache extension, we must use ->(p)connect
39 // for the first connection.
40 return $this->connect($host, $port, $persistent);
46 public function getMemcache() {
47 return $this->memcache;
53 public function close() {
54 $this->memcache->close();
58 * Connects to a memcache server.
61 * The server path without port.
64 * @param bool $persistent
65 * Whether this server connection is persistent or not.
67 * @return \Memcache|bool
68 * A Memcache object for a successful persistent connection. TRUE for a
69 * successful non-persistent connection. FALSE when the server fails to
72 protected function connect($host, $port, $persistent) {
74 return @$this->memcache->pconnect($host, $port);
77 return @$this->memcache->connect($host, $port);