X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fmemcache%2Fsrc%2FConnection%2FMemcacheConnection.php;fp=web%2Fmodules%2Fcontrib%2Fmemcache%2Fsrc%2FConnection%2FMemcacheConnection.php;h=83e507591c7adf9ee0ead0167ad95e3e4058ad66;hp=0000000000000000000000000000000000000000;hb=059867c3f96750652c80f39e44c442a58c2549ee;hpb=f8fc16ae6b862bef59baaad5d051dd37b7ff11b2 diff --git a/web/modules/contrib/memcache/src/Connection/MemcacheConnection.php b/web/modules/contrib/memcache/src/Connection/MemcacheConnection.php new file mode 100644 index 000000000..83e507591 --- /dev/null +++ b/web/modules/contrib/memcache/src/Connection/MemcacheConnection.php @@ -0,0 +1,81 @@ +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); + } + } + +}