You are here

public static function DrupalMemcachedUtils::parseServerInfo in Memcache Storage 8

Parses the string of memcached server.

Parameters

$memcached_server string: Examples of server string:

  • unix:///path/to/memcached.socket
  • 127.0.0.1:12111

Return value

array Processed host and port values.

2 calls to DrupalMemcachedUtils::parseServerInfo()
DrupalMemcachedBase::addServers in src/DrupalMemcachedBase.php
memcache_storage_requirements in ./memcache_storage.install
Implements hook_requirements().

File

src/DrupalMemcachedUtils.php, line 20

Class

DrupalMemcachedUtils

Namespace

Drupal\memcache_storage

Code

public static function parseServerInfo($memcached_server) {
  list($host, $port) = explode(':', $memcached_server);

  // Support unix sockets in the format 'unix:///path/to/socket'.
  if ($host == 'unix') {

    // PECL Memcache requires string format like 'unix:///path/to/socket' to
    // establish a connection, while PECL Memcached requires only
    // '/path/to/socket' string for the same purpose.
    $pecl_extension = self::getPeclExtension();
    $host = $pecl_extension == 'Memcached' ? substr($memcached_server, 7) : $memcached_server;

    // For unix sockets port is always 0.
    $port = 0;
  }
  return [
    $host,
    $port,
  ];
}