MemcacheCacheDriver.php: add detailed errors

This commit is contained in:
Zankaria 2025-05-31 18:08:54 +02:00
parent 2b30929bc9
commit 7aae8be1ae

View file

@ -13,10 +13,12 @@ class MemcachedCacheDriver implements CacheDriver {
public function __construct(string $prefix, string $server_uri, int $server_port, int $server_weight) {
$this->inner = new \Memcached();
if (!$this->inner->setOption(\Memcached::OPT_BINARY_PROTOCOL, true)) {
throw new \RuntimeException('Unable to set the memcached protocol!');
$err = $this->inner->getResultMessage();
throw new \RuntimeException("Unable to set the memcached protocol: '$err'");
}
if (!$this->inner->setOption(\Memcached::OPT_PREFIX_KEY, $prefix)) {
throw new \RuntimeException('Unable to set the memcached prefix!');
$err = $this->inner->getResultMessage();
throw new \RuntimeException("Unable to set the memcached prefix: '$err'");
}
$maybe_unix_path = self::asUnixSocketPath($server_uri);
@ -38,11 +40,13 @@ class MemcachedCacheDriver implements CacheDriver {
if (!$found_in_curr) {
if (!empty($current_servers)) {
if ($this->inner->resetServerList()) {
throw new \RuntimeException('Unable to reset the memcached server list!');
$err = $this->inner->getResultMessage();
throw new \RuntimeException("Unable to reset the memcached server list: '$err'");
}
}
if ($this->inner->addServer($server_uri, $server_port, $server_weight)) {
throw new \RuntimeException('Unable to add memcached servers!');
$err = $this->inner->getResultMessage();
throw new \RuntimeException("Unable to add memcached servers: '$err'");
}
}
}