phacility/phabricator · critical · Exception

Unable to connect to memcache server (%s:%d)!

Error message

Unable to connect to memcache server (%s:%d)!

What it means

PhutilMemcacheKeyValueCache opens a persistent connection per configured server with memcache_pconnect(). If the connection attempt fails (server down, wrong host/port, firewall, missing memcache extension), getConnection() throws this exception with the host and port it tried.

Source

Thrown at src/infrastructure/cache/PhutilMemcacheKeyValueCache.php:141

    }

    return $buckets;
  }


  /**
   * @phutil-external-symbol function memcache_pconnect
   */
  private function getConnection($server) {
    if (empty($this->connections[$server])) {
      $spec = $this->servers[$server];
      $host = $spec['host'];
      $port = $spec['port'];

      $conn = memcache_pconnect($host, $spec['port']);

      if (!$conn) {
        throw new Exception(
          pht(
            'Unable to connect to memcache server (%s:%d)!',
            $host,
            $port));
      }

      $this->connections[$server] = $conn;
    }
    return $this->connections[$server];
  }

}

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Verify the server is reachable from the web host: 'nc -vz <host> 11211' (or telnet), and start memcached if it is down.
  2. Check cluster.cache_servers in Phabricator config for typos and the intended host:port.
  3. Confirm the PHP memcache extension is installed and loaded ('php -m | grep memcache').
  4. Fix firewall/security-group rules so the web nodes can reach the cache port.
  5. As a stopgap, remove the broken server from cluster.cache_servers (or empty the list to fall back to local cache) until it is repaired.

Example fix

// before (cluster.cache_servers)
["cache-badhost.local:11211"]

// after
["cache.internal:11211"]
Defensive patterns

Strategy: try-catch

Validate before calling

// Preflight cache servers at boot before relying on them
foreach ($cache_servers as $server) {
  list($host, $port) = explode(':', $server);
  $sock = @fsockopen($host, $port, $errno, $errstr, 1);
  if (!$sock) {
    // flag the server unhealthy and alert; fall back to local cache
  }
  fclose($sock);
}

Try / catch

try {
  $cache->setKey($key, $value);
} catch (Exception $ex) {
  // degrade to the default on-disk/local cache for this request
  // and log the failed host:port for operators
}

Prevention

When it happens

Trigger: cluster.cache_servers lists a memcached host:port that is not listening; memcached stopped or crashed; typo in the host; PHP 'memcache' extension not installed (pconnect missing); network/firewall blocking the port between web nodes and the cache host.

Common situations: Fresh deployment where memcached was never started ('service memcached status'); config copied from another environment with an internal DNS name; container/VM restarts losing the daemon; scaling web nodes into a subnet without a firewall rule for 11211.

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/d0822a770ec15c0c. Report an issue: GitHub.