Write session to Memcache,sessionmemcache
Customizing session writes by Session_set_save_handler () method memcache
1
Php2 classmemsession{3 Private Static $handler=NULL;4 Private Static $lifetime=NULL;5 Private Static $time=NULL;6 ConstMS = ' Session ';7 8 Private Static functionInit$handler){9Self::$handler=$handler;TenSelf::$lifetime=Ini_get(' Session.gc_maxlifetime '); OneSelf::$time= Time(); A } - - Public Static functionStart$memcache){ theSelf::init ($memcache); - //call the method in the class to use an array, __class__ represents this class - Session_set_save_handler( - Array(__class__, ' open '), + Array(__class__, ' close '), - Array(__class__, ' read '), + Array(__class__, ' write '), A Array(__class__, ' Destroy '), at Array(__class__, ' GC ') - ); - Session_Start(); - } - - Public Static functionOpen$path,$name){ in - } to Public Static functionClose () { + - } the * Public Static functionRead$PHPSESSID){ $ $val= Self::$handler->get (Self::session_key ($PHPSESSID));Panax Notoginseng - if($val===false||$val==NULL){ the return false; + } A return $val; the } + Public Static functionWrite$PHPSESSID,$data){ - $method=$data? ' Set ': ' Replace '; $ returnSelf::$handler-$method(Self::session_key ($PHPSESSID),$data, Memcache_compressed,self::$lifetime); $ } - - Public Static functionDestroy$PHPSESSID){ the returnSelf::$handle->delete (Self::session_key ($PHPSESSID)); - }Wuyi //Memcache itself has a time limit, the data is automatically destroyed, so do not use GC method the Public Static functiongc$lifetime){ - return true; Wu } - About //prefix SessionID to avoid key duplication $ Private Static functionSession_key ($PHPSESSID){ - $session _key= Self::ms.$PHPSESSID; - return $session _key; - } A } + $mem=NewMemcache; the $mem->connect ("localhost", 11211) or die("Could Not connect"); -Memsession::start ($mem);
http://www.bkjia.com/PHPjc/980027.html www.bkjia.com true http://www.bkjia.com/PHPjc/980027.html techarticle Write Session Memcache,sessionmemcache by Session_set_save_handler () method to customize session write Memcache 1? PHP 2 class memsession{ 3 private static $handler = null; 4 pri ...