<? PHP class memsession {Private Static $ handler = NULL; Private Static $ lifetime = NULL; Private Static $ time = NULL; const NS = 'session _'; private Static function Init ($ handler) {self ::$ handler = $ handler; self ::$ lifetime = ini_get ('session. gc_maxlifetime '); self: $ time = Time ();} public static function start (memcache $ memcache) {self: Init ($ memcache ); session_set_save_handler (Array (_ class __, "open"), array (_ Class __, "close"), array (_ class __, "read"), array (_ class __, "write "), array (_ class __, "Destroy"), array (_ class __, "GC"); session_start ();} public static function open ($ path, $ name) {return true;} public static function close () {return true;} public static function read ($ PHPSESSID) {$ out = self :: $ Handler-> get (SELF: session_key ($ PHPSESSID); If ($ out = false | $ out = NULL) {return '';} return $ Out;} public static function write ($ PHPSESSID, $ data) {$ method = $ data? 'Set': 'replace '; return self: $ Handler-> $ method (SELF: session_key ($ PHPSESSID), $ data, memcache_compressed, self :: $ lifetime);} public static function destroy ($ PHPSESSID) {return self ::$ Handler-> Delete (SELF: session_key ($ PHPSESSID ));} public static function GC ($ lifetime) {return true;} Private Static function session_key ($ PHPSESSID) {$ session_key = self: ns. $ PHPSESSID; return $ session_key; }}$ memcac He = new memcache; $ memcache-> connect ("localhost", 11211) or die ("cocould not connect memcache"); memsession: Start ($ memcache ); /* foreach ($ options ['servers'] as $ server) {$ this-> Handler-> $ addserver ($ server ['IP'], $ server ['Port']); // echo $ server ['IP'];} */?>