Re: Memcache session handler
| From: | Mikael Johansson | Date: | Mon, 23 Oct 2006 18:45:22 +0000 |
| Subject: | Re: Memcache session handler | ||
| References: | 1 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-4280@lists.php.net to get a copy of this message | ||
I agree with Antony, there shouldn't be a problem integrating session
handling into pecl/memcache. Some questions though
* The extension needs to know the address of the servers in order to
connect, so how do you start the session?
1) From php.ini using something like
memcache.session_storage =
"tcp://node01.example.com:11211?weight=2,tcp://node02.example.com:11211"
session.save_handler = memcache
2) From your script as
$memcache = new Memcache();
$memcache->addServer(...);
$memcache->registerSessionHandler();
session_start();
* Memcache (as with any other cache) is inherently unreliable and might
garbage collect keys in a LRU fashion should it need the memory for
other keys. One might be able to mitigate this issue by ensuring that
memcache has plenty memory, but until there's a (per key) DO_NOT_GC flag
implemented in memcached there's always the risk of sessions being dropped.
Better to have a 2-tier session storage where writes are passed through
to a database (shared by all the web front ends) and reads are handled
by the cache. For example:
http://svn.synd.info/synd/trunk/core/lib/SessionHandler.class.inc
But if you need the performance of storing the session only in memcached
and are aware of the potential problems, you should be able to do so.
If you wouldn't mind posting a link to your code and a patch against the
current CVS head we'll try and integrate it as soon as possible.
//Mikael
Glenn Richmond wrote:
> Hi All,
>
> I've been having a look at using memcache for session handling in a
> clustered environment in order to achieve a shared session storage
> method. I have the basic functionality working and the code is fairly
> straight forward, so would like to make it part of the PECL memcache
> package if at all possible. I also noticed that someone else had a shot
> at creating the memcache session handler, but couldn't find it they ever
> checked it in or not.
>
> I discussed this with the main PHP-dev list, but the general opinion was
> that it should be made as a package, either as part of PECL-memcache or
> on its own. I'd prefer to make it part of PECL memcache as the memcache
> library can be shared.
>
> So, a couple of questions:
>
> * Are people generally happy that I should add a memcache session
> handler to the memcache PECL package? If not, recommendations?
> * If so, what is the process for doing this? i.e. is there a QA
> procedure that needs to be followed?
>
> Thanks,
>
> Glenn.
>