Write sessions to Memcache using session_set_save_handler () to customize the Session write into Memcache1 & lt ;? Php2classMemSession {3 privatestatic $ handlernull; 4 privatestatic $ li writes the Session to Memcache
Use session_set_save_handler () to customize the Session to write data to Memcache
1
Get (self: session_key ($ PHPSESSID); 37 38 if ($ val = false | $ val = null) {39 return false; 40} 41 return $ val; 42} 43 public static function write ($ PHPSESSID, $ data) {44 $ method = $ data? 'Set': 'Replace '; 45 return self: $ handler-> $ method (self: session_key ($ PHPSESSID), $ data, MEMCACHE_COMPRESSED, self :: $ lifetime); 46} 47 48 public static function destroy ($ PHPSESSID) {49 return self: $ handle-> delete (self: session_key ($ PHPSESSID )); 50} 51 // memcache has a limited time and data is automatically destroyed. Therefore, you do not need to use the gc method 52 public static function gc ($ lifetime) {53 return true; 54} 55 56 // prefix sessionID to avoid repeated key 57 private static function session_key ($ PHPSESSID) {58 $ session_key = self: MS. $ PHPSESSID; 59 return $ session_key; 60} 61} 62 $ mem = new Memcache; 63 $ mem-> connect ("localhost", 11211) or die ("cocould not connect"); 64 MemSession: start ($ mem );