0

以下是我的 Symfony 项目 services.yaml 的配置,[我正在尝试在 Redis Enterprise Cloud Memcached 上存储会话]

parameters:
   session_memcached_host: memcached-11999.someurl.redislabs.com
   session_memcached_port: 11999
   session_memcached_prefix: test
   session_memcached_expire: 3600 # this is in seconds
   session_memcached_user: abcd
   session_memcached_pass: abcd

services:
    session.memcached:
        class: Memcached
        arguments:
        calls:
           - [addServer, ['%session_memcached_host%','%session_memcached_port%']]
#           - [setSaslAuthData, ['%session_memcached_user%','%session_memcached_pass%']]
           - [setOption, [Memcached::OPT_BINARY_PROTOCOL, true]]

    session.handler.memcached:
        class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler
        arguments: ["@session.memcached", { prefix: '%session_memcached_prefix%', expiretime: '%session_memcached_expire%' }]

获取以下错误异常

in var/cache/dev/ContainerIG8bgiG/App_KernelDevDebugContainer.php (line 1635)

include_once \dirname(__DIR__, 4).'/vendor/symfony/http-foundation/Session/SessionBagInterface.php';
include_once \dirname(__DIR__, 4).'/vendor/symfony/http-foundation/Session/Storage/MetadataBag.php';        
$a = new \Memcached();       
$a->addServer('memcached-11999.someurl.redislabs.com', 11999);        
$a->setOption('Memcached::OPT_BINARY_PROTOCOL', true);        
return $this->privates['session.storage.native'] = new\Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage($this->parameters['session.storage.options'], new \Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler($a, ['prefix' => 'test', 'expiretime' => 3600]), new \Symfony\Component\HttpFoundation\Session\Storage\MetadataBag('_sf2_meta', 0));    }    /**

如果我取消注释以下行

- [setSaslAuthData, ['%session_memcached_user%','%session_memcached_pass%']]

然后它给出以下警告,因为它不支持没有二进制文件的 SASL

Warning: Memcached::setSaslAuthData(): SASL is only supported with binary protocol

获取以下错误异常

in var/cache/dev/ContainerNVvLqte/App_KernelDevDebugContainer.php (line 1635)

include_once \dirname(__DIR__, 4).'/vendor/symfony/http-foundation/Session/SessionBagInterface.php';        
include_once \dirname(__DIR__, 4).'/vendor/symfony/http-foundation/Session/Storage/MetadataBag.php';
$a = new \Memcached();
$a->addServer('memcached-11999.someurl.redislabs.com', 11999);
$a->setSaslAuthData('abcd', 'abcd');        
$a->setOption('Memcached::OPT_BINARY_PROTOCOL', true);        

return $this->privates['session.storage.native'] = new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage($this->parameters['session.storage.options'], new \Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler($a, ['prefix' => 'test', 'expiretime' => 3600]), 
new \Symfony\Component\HttpFoundation\Session\Storage\MetadataBag('_sf2_meta', 0));    }

4

1 回答 1

0

我不明白为什么 Symfony 仅在将第一个参数 'Memcached::OPT_BINARY_PROTOCOL' 添加到 services.yaml 时才考虑将其作为字符串!

我通过启用默认 memcached.default_binary_protocol 解决了这个问题

我在 /etc/php/7.2/mods-available/memcached.ini 中添加了这一行

memcached.default_binary_protocol = On

检查 info.php 的屏幕截图

以下是我对 Symfony 项目的 services.yaml 文件的最终配置

parameters:
   session_memcached_host: memcached-11999.someurl.redislabs.com
   session_memcached_port: 11999
   session_memcached_prefix: test
   session_memcached_expire: 3600 # this is in seconds
   session_memcached_user: abcd
   session_memcached_pass: abcd

services:
    session.memcached:
        class: Memcached
        arguments:
        calls:
           - [setSaslAuthData, ['%session_memcached_user%','%session_memcached_$
           - [addServer, ['%session_memcached_host%','%session_memcached_port%'$

    session.handler.memcached:
        class: Symfony\Component\HttpFoundation\Session\Storage\Handler\Memcach$
        arguments: ["@session.memcached", { prefix: '%session_memcached_prefix%$

现在它在 Redislabs Memcached 上存储会话 :)

于 2019-12-10T14:28:39.500 回答