#1 By: douglaswross, June 1st, 2014 05:53
Trying to setup sessions in php symfony2 framework using memcachier.
Memcachier requires SASL to connect, and you have very nicely enables SASL in the memcached build.
I cannot see how to configure symfony2 to connect using SASL with memcached to memcachier.
Has anyone successfully got it to work. I have tried configuring symfony2 to do it, however I think that there must be an easier way - as anyone doing php with more than one dyno will need to manage sessions in some store that is common to all dynos, and memcachier on Heroku seems like a common way to do it?
Thanks anyone for assistance
#2 By: David Zuelke, June 1st, 2014 10:05
ext/memcached has two undocumented
php.ini options for SASL and sessions,
The easiest way of configuring it appropriately for Heroku is probably to use a
.user.ini in your document root (see https://devcenter.heroku.com/articles/custom-php-settings#user-ini-files-recommended), since you can configure the sessions there by referencing environment variables:
As SASL has a bit of overhead on connecting, however, it might be a good idea to make the session connection persistent, which you can do using a prefix for the session save path (again undocumented, unfortunately):
Potentially, you can wrap that up into your own variant of https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeFileSessionHandler.php
You can also use Symfony's
Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler and pass it a
Memcached instance that has the binary protocol enabled and where you called
setSaslAuthData() before. Make sure the connection is also persistent for better performance.
Hope that helps!
P.S. You can of course also just use a bunch of
ini_set() calls (with
getenv() to fetch the
MEMCACHIER_* config vars) instead of a
#3 By: douglaswross, June 16th, 2014 10:17
Thanks I got it working using your instructions - thanks very much
#4 By: douglaswross, September 9th, 2014 08:05
We are having some troubles with session management using memcached.
Every once and a while the session gets dropped, and I am wondering if I have multiple session handlers running rather than just memcached.
i.e. in phpinfo - when I set up as in this post using .user.ini, I get the following:
Session Support enabled
Registered save handlers files user memcached
Do you think that potentially I need to remove files and user as registered handlers, and maybe php is sometimes using memcached, and sometimes using files and this is why the session is flaky?
Do you know how I could remove files and user as possible registered save handlers, or increase the priority of memcached, so that is all that is used? Or do I need to branch the heroku buildpack, and then update the php.ini file you provide by default?
#5 By: David Zuelke, September 9th, 2014 11:39
No, that's not what is happening. It simply means that those handlers are available, not that they are being used.
Memcached sometimes loses information; it's designed to (it shouldn't unless the entire store is fully used, but I've seen it happen too). Have you considered using a different storage backend such as MongoDB or Redis?
What are the Memcachier folks saying about it?