{"record":{"id":"d0822a770ec15c0c","repo":"phacility/phabricator","slug":"unable-to-connect-to-memcache-server-s-d","errorCode":null,"errorMessage":"Unable to connect to memcache server (%s:%d)!","messagePattern":"Unable to connect to memcache server \\((.+?):(.+?)\\)!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"src/infrastructure/cache/PhutilMemcacheKeyValueCache.php","lineNumber":141,"sourceCode":"    }\n\n    return $buckets;\n  }\n\n\n  /**\n   * @phutil-external-symbol function memcache_pconnect\n   */\n  private function getConnection($server) {\n    if (empty($this->connections[$server])) {\n      $spec = $this->servers[$server];\n      $host = $spec['host'];\n      $port = $spec['port'];\n\n      $conn = memcache_pconnect($host, $spec['port']);\n\n      if (!$conn) {\n        throw new Exception(\n          pht(\n            'Unable to connect to memcache server (%s:%d)!',\n            $host,\n            $port));\n      }\n\n      $this->connections[$server] = $conn;\n    }\n    return $this->connections[$server];\n  }\n\n}\n","sourceCodeStart":123,"sourceCodeEnd":154,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/infrastructure/cache/PhutilMemcacheKeyValueCache.php#L123-L154","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the server is reachable from the web host: 'nc -vz <host> 11211' (or telnet), and start memcached if it is down.","Check cluster.cache_servers in Phabricator config for typos and the intended host:port.","Confirm the PHP memcache extension is installed and loaded ('php -m | grep memcache').","Fix firewall/security-group rules so the web nodes can reach the cache port.","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."],"exampleFix":"// before (cluster.cache_servers)\n[\"cache-badhost.local:11211\"]\n\n// after\n[\"cache.internal:11211\"]","handlingStrategy":"try-catch","validationCode":"// Preflight cache servers at boot before relying on them\nforeach ($cache_servers as $server) {\n  list($host, $port) = explode(':', $server);\n  $sock = @fsockopen($host, $port, $errno, $errstr, 1);\n  if (!$sock) {\n    // flag the server unhealthy and alert; fall back to local cache\n  }\n  fclose($sock);\n}","typeGuard":null,"tryCatchPattern":"try {\n  $cache->setKey($key, $value);\n} catch (Exception $ex) {\n  // degrade to the default on-disk/local cache for this request\n  // and log the failed host:port for operators\n}","preventionTips":["Monitor memcached (process alive, port reachable) with the same host/port used in cluster.cache_servers.","Keep cluster.cache_servers accurate per environment; never copy it between environments blindly.","Confirm the PHP memcache extension is installed on every web node.","Run memcached under a supervisor so it restarts automatically."],"tags":["phabricator","memcache","cache","infrastructure","network"],"backgroundTag":"memcache-connection-failed","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}