Skip to content

Configuration validation issue with Memcached socket (path) #853

Closed
@leegarner

Description

@leegarner

Configuration

  • PhpFastCache version: 8.1.1/9.0.1
  • PhpFastCache API version: 3.0.0
  • PHP version: 7.3 and 8.1
  • Operating system: Ubuntu 20.04

Describe the bug
Unable to add a path to a Memcached socket. Adding the path to the server config results in
PHP Fatal error: Uncaught Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException: Unknown keys for memcached server: path in /tmp/fastcache/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcached/Config.php:121

Adding 'path' to the 2nd array check in Config.php seems to solve the issue, and the socket does work

-- a/private/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcached/Config.php
+++ b/private/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcached/Config.php
@@ -117,7 +117,7 @@ class Config extends ConfigurationOption
             if ($diff = array_diff(['host', 'port', 'saslUser', 'saslPassword'], array_keys($server))) {
                 throw new PhpfastcacheInvalidConfigurationException('Missing keys for memcached server: ' . implode(', ', $diff));
             }
-            if ($diff = array_diff(array_keys($server), ['host', 'port', 'saslUser', 'saslPassword'])) {
+            if ($diff = array_diff(array_keys($server), ['path', 'host', 'port', 'saslUser', 'saslPassword'])) {
                 throw new PhpfastcacheInvalidConfigurationException('Unknown keys for memcached server: ' . implode(', ', $diff));
             }
             if (!is_string($server['host'])) {
@@ -186,4 +186,4 @@ class Config extends ConfigurationOption
         $this->optPrefix = trim($optPrefix);
         return $this;
     }```

**To Reproduce**
Steps to reproduce the behavior:
1. Add a socket path to the servers provided to the config.```$cm = CacheManager::getInstance('Memcached', new MemcachedConfig([
    'servers' => [
        [
            'host' => '127.0.0.1',
            'port' => 11211,
            'path' => '/var/run/memcache/memcached.sock',
            'saslUser' => null,
            'saslPassword' => null,
        ]
    ]
]));```

**Expected behavior**
Normal cache connection and usage

**Screenshots**
n/a

**Additional context**

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions