更新到PHP7後,我的應用程序會話處理有一些問題。自定義session_handler與php7(session_set_save_handler)斷開
它似乎並沒有成爲一個大問題,但PHP拋出這個錯誤每次:
[18-Jun-2016 20:49:10 UTC] PHP Warning: session_decode(): Session is not active. You cannot decode session data in /var/www/app/phpsessionredis.php on line 90
的session_handler什麼特別的。它將JSON化sessiondata存儲到redis等。
class phpsessionredis implements \SessionHandlerInterface {
public function __construct(&$redis) {
$this->__rc = $redis;
}
public function open($savePath, $sessionName) {
return true;
}
public function destroy($id) {
try { $this->__rc->del($id); }
catch (\RedisException $e) { return false; }
}
public function close() {
return true;
}
public function write($id, $data) {
session_decode($data); // throws an error
try{
$this->__rc->setex($id, 3600, json_encode($_SESSION));
} catch (\RedisException $e) { return false; }
return true;
}
public function read($id) {
try {
$r = $this->__rc
->multi()
->get($id)
->expire($id, 3600)
->exec();
} catch (\RedisException $e) { return false; }
$_SESSION = json_decode($r[0], true);
if(isset($_SESSION) && ! empty($_SESSION) && $_SESSION != null){
return session_encode();
}
return '';
}
public function gc($maxLifetime) {
return true;
}
}
$sessionhandler = new phpsessionredis($redis);
session_set_save_handler($sessionhandler);
ob_start();
session_start();
任何幫助都是值得歡迎的。
THX。 ( 遲到總比不到好 ) – user2429266