to allow other code (eg. the SyncML code from Horde) to open the eGW session, we use a first memcache key identical to the original memcache session handler (for the first junk/1MB)

This commit is contained in:
Ralf Becker 2007-08-17 15:53:19 +00:00
parent 4c59fcbc76
commit f17e9b4032

View File

@ -4,7 +4,10 @@
* *
* Fixes a problem of the buildin session handler of the memcache pecl extension, * Fixes a problem of the buildin session handler of the memcache pecl extension,
* which can NOT work with sessions > 1MB. This handler splits the session-data * which can NOT work with sessions > 1MB. This handler splits the session-data
* in 1MB junk, so memcache can handle them. * in 1MB junk, so memcache can handle them. For the first junk we use an identical
* key (just the session-id) as the original memcache session handler. For the further
* junks we add -2, -3, ... so other code (eg. the SyncML code from Horde) can
* open the session, if it's size is < 1MB.
* *
* To enable it, you need to set session.save_handler to 'memcache' and * To enable it, you need to set session.save_handler to 'memcache' and
* session.save_path to 'tcp://host:port[,tcp://host2:port,...]', * session.save_path to 'tcp://host:port[,tcp://host2:port,...]',
@ -44,8 +47,7 @@ function egw_memcache_read($id)
{ {
global $egw_memcache_obj; global $egw_memcache_obj;
$id = 'sess-'.$_REQUEST['domain'].'-'.$id; for($data=false,$n=0; ($read = $egw_memcache_obj->get($id.($n?'-'.$n:''))); ++$n)
for($data=false,$n=0; ($read = $egw_memcache_obj->get($id.'-'.$n)); ++$n)
{ {
$data .= $read; $data .= $read;
} }
@ -62,10 +64,9 @@ function egw_memcache_write($id, $sess_data)
{ {
$lifetime = 600; $lifetime = 600;
} }
$id = 'sess-'.$GLOBALS['egw_info']['user']['domain'].'-'.$id;
for($n=$i=0,$len=_bytes($sess_data); $i < $len; $i += MEMCACHED_MAX_JUNK,++$n) for($n=$i=0,$len=_bytes($sess_data); $i < $len; $i += MEMCACHED_MAX_JUNK,++$n)
{ {
if (!$egw_memcache_obj->set($id.'-'.$n,_cut_bytes($sess_data,$i,MEMCACHED_MAX_JUNK),0,$lifetime)) return false; if (!$egw_memcache_obj->set($id.($n?'-'.$n:''),_cut_bytes($sess_data,$i,MEMCACHED_MAX_JUNK),0,$lifetime)) return false;
} }
return true; return true;
} }
@ -97,8 +98,7 @@ function egw_memcache_destroy($id)
{ {
global $egw_memcache_obj; global $egw_memcache_obj;
$id = 'sess-'.$_REQUEST['domain'].'-'.$id; for($n=0; $egw_memcache_obj->delete($id.($n?'-'.$n:'')); ++$n) ;
for($n=0; $egw_memcache_obj->delete($id.'-'.$n); ++$n) ;
return $n > 0; return $n > 0;
} }