我有當會話數據比內存緩存的1MB大障礙本次發行前。我通過在將會話數據存儲在Memcache中之前對其進行壓縮來解決此問題。
下面是我使用的代碼:
<?php
class SessionHandler {
public $lifeTime;
public function __construct() {
$this->lifeTime = intval(ini_get("session.gc_maxlifetime"));
session_set_cookie_params(0,"/",".domain.com",false,true);
session_name("SITESESSION");
session_set_save_handler(array (&$this,"open"),array (&$this,"close"),array (&$this,"read"),array (&$this,"write"),array (&$this,"destroy"),array (&$this,"gc"));
session_start();
}
public function open($savePath,$sessionName) {
return true;
}
public function close() {
return true;
}
public function read($sessionID) {
# The default miss for MC is (bool) false, so return it
return MC::get("userSession_{$sessionID}");
}
public function write($sessionID,$data) {
# This is called upon script termination or when session_write_close() is called, which ever is first.
return MC::set("userSession_{$sessionID}",$data,$this->lifeTime,true); # The last true sets it as compressed.
}
public function destroy($sessionID) {
# Called when a user logs out...
return MC::delete("userSession_{$sessionID}");
}
public function gc($maxlifetime) {
# The MC keys expire on their own, no need to do anything here.
return true;
}
}
?>
嗨PureForm。不幸的是,這不是我的情況,因爲會話數據非常小 – Thomas 2010-11-19 09:23:40