Commit cd5df57a authored by Phizes's avatar Phizes Committed by Jeremy

Issue #1690130 by Phizes: Support sockets with PECL memcached extension.

parent f173ea71
......@@ -55,7 +55,8 @@ pattern:
'memcache_servers' => array(
host1:port => cluster,
host2:port => cluster,
hostN:port => cluster
hostN:port => cluster,
'unix:///path/to/socket' => cluster
)
'memcache_bins' => array(bin1 => cluster, bin2 => cluster, binN => cluster)
......@@ -74,20 +75,26 @@ The bin/cluster/server model can be described as follows:
- The default cluster is 'default'.
Here is a simple setup that has two memcached instances, both running on
localhost. The 11212 instance belongs to the 'pages' cluster and the table
cache_page is mapped to the 'pages' cluster. Thus everything that gets cached,
with the exception of the page cache (cache_page), will be put into 'default',
or the 11211 instance. The page cache will be in 11212.
Here is a simple setup that has three memcached instances, two running on
localhost, and one on a Unix socket. The 11212 instance belongs to the 'pages'
cluster and the table cache_page is mapped to the 'pages' cluster. The Unix
socket instance belongs to the 'blocks' cluster, and the table cache_block is
mapped to the 'blocks' cluster. Thus everything that gets cached, with the
exception of the page cache (cache_page) and block cache (cache_block), will be
put into 'default', or the 11211 instance. The page cache will be in 11212, and
the block cache in the Unix socket instance. Note that no port is specified for
the socket.
$conf = array(
...
// Important to define a default cluster in both the servers
// and in the bins. This links them together.
'memcache_servers' => array('localhost:11211' => 'default',
'localhost:11212' => 'pages'),
'localhost:11212' => 'pages',
'unix:///path/to/socket' => 'blocks'),
'memcache_bins' => array('cache' => 'default',
'cache_page' => 'pages'),
'cache_page' => 'pages',
'cache_block' => 'blocks'),
);
Here is an example configuration that has two clusters, 'default' and
......
......@@ -365,16 +365,15 @@ function dmemcache_object($bin = NULL, $flush = FALSE) {
if ($c == $cluster && !isset($failed_connection_cache[$s])) {
list($host, $port) = explode(':', $s);
// Support unix sockets in the format 'unix:///path/to/socket'.
if ($host == 'unix') {
// When using unix sockets use the full path for $host.
$host = $s;
// Port is always 0 for unix sockets.
$port = 0;
}
// Using the Memcache PECL extension.
if ($memcache instanceof Memcache) {
// 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 = $s;
// Port is always 0 for unix sockets.
$port = 0;
}
// When using the PECL memcache extension, we must use ->(p)connect
// for the first connection.
if (!$init) {
......@@ -398,8 +397,17 @@ function dmemcache_object($bin = NULL, $flush = FALSE) {
$memcache->addServer($host, $port, $memcache_persistent);
}
}
else if ($memcache->addServer($host, $port) && !$init) {
$init = TRUE;
else {
// Support unix sockets in the format 'unix:///path/to/socket'.
if ($host == 'unix') {
// Memcached expects just the path to the socket without the protocol
$host = substr($s, 7);
// Port is always 0 for unix sockets.
$port = 0;
}
if ($memcache->addServer($host, $port) && !$init) {
$init = TRUE;
}
}
if (!$init) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment