{"record":{"id":"a49f001f7a6228fd","repo":"symfony/symfony","slug":"memcachedadapter-client-error-s","errorCode":null,"errorMessage":"MemcachedAdapter client error: %s","messagePattern":"MemcachedAdapter client error: (.+?)","errorType":"exception","errorClass":"CacheException","httpStatus":null,"severity":"error","filePath":"src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php","lineNumber":301,"sourceCode":"        }\n\n        return $ok;\n    }\n\n    protected function doClear(string $namespace): bool\n    {\n        return '' === $namespace && $this->getClient()->flush();\n    }\n\n    private function checkResultCode(mixed $result): mixed\n    {\n        $code = $this->client->getResultCode();\n\n        if (\\Memcached::RES_SUCCESS === $code || \\Memcached::RES_NOTFOUND === $code) {\n            return $result;\n        }\n\n        throw new CacheException('MemcachedAdapter client error: '.strtolower($this->client->getResultMessage()));\n    }\n\n    private function getClient(): \\Memcached\n    {\n        if (isset($this->client)) {\n            return $this->client;\n        }\n\n        $opt = $this->lazyClient->getOption(\\Memcached::OPT_SERIALIZER);\n        if (\\Memcached::SERIALIZER_PHP !== $opt && \\Memcached::SERIALIZER_IGBINARY !== $opt) {\n            throw new CacheException('MemcachedAdapter: \"serializer\" option must be \"php\" or \"igbinary\".');\n        }\n        if ('' !== $prefix = (string) $this->lazyClient->getOption(\\Memcached::OPT_PREFIX_KEY)) {\n            throw new CacheException(\\sprintf('MemcachedAdapter: \"prefix_key\" option must be empty when using proxified connections, \"%s\" given.', $prefix));\n        }\n\n        return $this->client = $this->lazyClient;\n    }","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/symfony/symfony/blob/3b11ffbe2520436b0951974d1993dc2144f91dd3/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php#L283-L319","documentation":"Thrown by MemcachedAdapter::checkResultCode() after a Memcached operation returns a result code other than RES_SUCCESS or RES_NOTFOUND. The message embeds the lowercased libmemcached result message (replacing %s), so it surfaces the underlying client failure (e.g. connection refused, write failure, partial timeout, server marked dead).","triggerScenarios":"Any cache operation (save, delete, flush, increment) where $this->client->getResultCode() returns a non-success, non-notfound code — e.g. memcached server is down/unreachable, network partition, item too large, bad key, server flushed/evicted under foot, or libmemcached marking all servers dead.","commonSituations":"Memcached process not running or restarted (connection errors); firewall/network blocking the 11211 port; persistent_id reuse across clusters; values exceeding memcached item size limit (~1MB); exhausted or evicted memory; deploying without the memcached service in the container/compose setup.","solutions":["Verify the memcached service is running and reachable from the PHP process: telnet host 11211 or nc -z host 11211.","Inspect the exact result message in the exception text to map it to a libmemcached RES_* cause and address that specifically.","Check container/compose service definitions and env vars point at the correct host/port.","If item-too-large, reduce payload size or raise memcached -I (max item size) and -m (memory) on the server.","For transient network blips, consider a retry/backoff wrapper or failover pool, but never swallow the exception silently."],"exampleFix":"// before — assume cache always works\n$pool->get('key', fn() => expensive());\n\n// after — surface infrastructure problems\ntry {\n    $pool->get('key', fn() => expensive());\n} catch (\\Symfony\\Component\\Cache\\Exception\\CacheException $e) {\n    // log full message which includes the libmemcached result text\n    $logger->error('Cache failure: '.$e->getMessage());\n    throw $e;\n}","handlingStrategy":"try-catch","validationCode":"// preflight reachability before relying on the pool\nfunction memcachedReachable(string $host, int $port=11211): bool {\n    $fp = @fsockopen($host, $port, $errno, $errstr, 1);\n    if (is_resource($fp)) { fclose($fp); return true; }\n    return false;\n}","typeGuard":null,"tryCatchPattern":"try {\n    $item = $pool->get('key', $callback);\n} catch (\\Symfony\\Component\\Cache\\Exception\\CacheException $e) {\n    $logger->error('Memcached op failed: '.$e->getMessage());\n    // only fall back if you intentionally have a fallback pool\n    return $callback();\n}","preventionTips":["Run health checks against memcached in your orchestrator so dead nodes are detected before traffic.","Log the result message from every CacheException — it carries the libmemcached RES_* reason.","Keep individual cache values well under memcached's 1MB item limit.","Never swallow CacheException silently; decide on an explicit fallback or rethrow."],"tags":["memcached","cache","runtime","network","cache-exception"],"backgroundTag":null,"analyzedSha":"3b11ffbe2520436b0951974d1993dc2144f91dd3","analyzedAt":"2026-08-11T22:13:02.001Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}