memcached提供了一个自定义的session处理器可以被用于存储用户session数据到memcached服务端。 一个完全独立的memcached实例将会在内部使用,因此如果需要您可以设置一个不同的服务器池。session的 key被存储在前缀memc.sess.key.之下,因此, 如果你对session和通常的缓存使用了 同样的服务器池,请注意这一点。 译注:另外一个session和通常缓存分离的原因是当通常的缓存占满了memcached服务端后,可能会导致你的session被 从缓存中踢除,导致用户莫名的掉线。
richard at fussenegger dot info (2013-06-16 20:56:04)
The documentation is not complete, you can also pass the weight of each server and you can use sockets if you want. In your PHP ini:
<?php
// Sockets with weight in the format socket_path:port:weight
session.save_path = "/path/to/socket:0:42"
// Or more than one so that weight makes sense?
session.save_path = "/path/to/socket_x:0:42,/path/to/socket_y:0:666"
?>
And if you should ever want to access these servers in PHP:
<?php
$servers = explode(",", ini_get("session.save_path"));
$c = count($servers);
for ($i = 0; $i < $c; ++$i) {
$servers[$i] = explode(":", $servers[$i]);
}
$memcached = new \Memcached();
call_user_func_array([ $memcached, "addServers" ], $servers);
print_r($memcached->getAllKeys());
?>
taubers at gmail dot com (2012-10-04 23:42:38)
If you are using the memcache class for session handling your key is the PHP session ID. This is different than when using the memcached class.
Example with memcache:
GET nphu2u8eo5niltfgdbc33ajb62
Example with memcached:
GET memc.sess.key.nphu2u8eo5niltfgdbc33ajb62
For memcached, the prefix is set in the config:
memcached.sess_prefix = "memc.sess.key."
sstratton at php dot net (2011-06-14 12:48:55)
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.
nfoo at naver dot com (2010-08-28 00:15:04)
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 (2009-05-27 07:56:24)
This extension supports Session-locking!
by default
MEMC_SESS_LOCK_ATTEMPTS 30
MEMC_SESS_LOCK_WAIT 100000
MEMC_SESS_LOCK_EXPIRATION 30