Leaseweb / LswMemcacheBundle

Symfony bundle for Memcache Doctrine caching and session storage in the Web Debug Toolbar.
MIT License
202 stars 57 forks source link

What value should be used as handler_id in config.yml? #91

Closed gmansilla closed 7 years ago

gmansilla commented 7 years ago

In my case, I have multiple instances of my app running behind a load balancer, that's why I wanted to save sessions in memcached in the first place.

What should I use as handler_id in config.yml? If I leave this null, then it'll use the default session handler from php.ini

framework:
    session:
        gc_probability: 0
        handler_id: # ?
gmansilla commented 7 years ago

For those having the same problem I had:

1) The handler id is a reference to an actual Service defined in your services.yml file.

2) Since this bundle is a wrapper for the [Memcached] class you can either extend it or use the base class.

That being said, you could do something like

my.memcached.service:
    class: Memcached
    calls:
        - [addServer, ['memcached_address', 'memcached_port']] 

my.memcached.session.handler:
    class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler
   arguments:
       - "@my.memcached.service"
       - prefix: 'your_prefix'
       - expiretime: 'your_expire_time'
mevdschee commented 7 years ago

@gmansilla Note that that session handler does not implement locking.

see: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcachedSessionHandler.php

gmansilla commented 7 years ago

Right, so if you want to have locking available you must replace

"Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler" with "Lsw\MemcacheBundle\Session\Storage\LockingSessionHandler".

I think this is worth mentioning in the README file. Should I create PR for this?

mevdschee commented 7 years ago

Yes.. good idea.. although I won't be the one merging it.

gmansilla commented 7 years ago

Fair enough. I'll create the PR.