Kangt_qc
Kangt_qc

Reputation: 420

Can't connect symfony 2.1.2 to memcache to store sessions

I'm trying to host my sessions in memcache server using sf2 framework. here is the config I have : in config.yml

framework:
    ...
    session:
        handler_id: session.handler.mc
...
services:
    session.memcache:
        class: Memcache
        calls:
            - [addServer , [%session_memcache_host%, %session_memcache_port%]]
    session.handler.mc:
        class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler
        arguments: [@session.memcache]

and in parameters I've set up my info like that :

session_memcache_host: memcachesession.lan
session_memcache_port: 11211

in my controller I have this :

public function indexAction()
{
    $session = new Session();
    $session->start();
    var_dump($session->getId());
    $session->set('foo','bar');
    $session->save();
    var_dump(session_id());
    var_dump($_SESSION);
    return array('name' => 'test');
}

And still I don't have my session in memcache ... I can't figure out why. Any help would appreciated, thanks.

Upvotes: 0

Views: 1261

Answers (1)

Kangt_qc
Kangt_qc

Reputation: 420

services:
session.memcache:
    class: Memcache
    calls:
        - [addServer , [%session_memcache_host%, %session_memcache_port%]]
session.handler.mc:
    class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler
    arguments: [@session.memcache, {prefix: ""}]

The main point here was to set an empty prefix ... so I have my real session name ... the one I have in my others application. Everything is ok now

Upvotes: 1

Related Questions