Memcached
在线手册:中文 英文
PHP手册

Sessions支持

memcached提供了一个自定义的session处理器可以被用于存储用户session数据到memcached服务端。 一个完全独立的memcached实例将会在内部使用,因此如果需要您可以设置一个不同的服务器池。session的 key被存储在前缀memc.sess.key.之下,因此, 如果你对session和通常的缓存使用了 同样的服务器池,请注意这一点。 译注:另外一个session和通常缓存分离的原因是当通常的缓存占满了memcached服务端后,可能会导致你的session被 从缓存中踢除,导致用户莫名的掉线。

session.save_handler string

设置为memcached开启memcached的session处理器。

session.save_path string

定义一个逗号分隔的hostname:port样式的session缓存服务器池,例如: "sess1:11211, sess2:11211".


Memcached
在线手册:中文 英文
PHP手册
PHP手册 - N: Sessions支持

用户评论:

sstratton at php dot net (14-Jun-2011 08:48)

While the previous poster has a point that Memcached can and will cleanup to make room for it's keys, the likelihood of active sessions (due to the likelihood that they will be written to again within 30 seconds) is fairly low provided you have your memory allocation properly alloted.

Tobias (17-Feb-2011 03:35)

You probably don't want to use Memcache, Memcached or anything else similar for storing sessions (in RAM via memcached daemon server), because those sessions can easily be thrown away/discarded, become unreachable for various reasons, and then your user gets logged out without warning.

What memcache is great for, in general, is storing the results of an SQL or MongoDB query, using the md5() has of the query itself as the key lookup.

For example, for all database queries, get the md5() hash of the query, then look for that key in memcache.  If it's found, great, grab the results, check they're not too old / outdated, and use them if okay.  Otherwise, pass through the query to underlying storage-based DB, then save its results into memcache before passing them back to your app.

This general applicability of how, when, where and why to use memcache to greatest advantage and least pain isn't so easy to find on the web.

Memcached module is great for new features, etc. (except now it's almost one year since update) but it's difficult to tell when a memcached daemon goes away, crashes, becomes unreachable.

Memcache at least has ->connect() method which will report failure/unreachability, but its features are behind.

These two projects are moving targets, competing, and it would be nice to get both together, so we can all benefit from best efforts.  Meanwhile, what a mess, and what a charm!

nfoo at naver dot com (28-Aug-2010 08:15)

If you want to use 'memcacheD' extention not 'memcache' (there are two diffrent extentions) for session control,  you should pay attention to modify php.ini

Most web resource from google is based on memcache because It's earlier version than memcacheD. They will say as following

session.save_handler = memcache
session.save_path = "tcp://localhost:11211"

But it's not valid when it comes to memcacheD

you should modify php.ini like that

session.save_handler = memcached
session.save_path = "localhost:11211"

Look, there is no protocol indentifier

Andrei Darashenka (27-May-2009 03:56)

This extension supports Session-locking!

by default
MEMC_SESS_LOCK_ATTEMPTS   30
MEMC_SESS_LOCK_WAIT       100000
MEMC_SESS_LOCK_EXPIRATION 30