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化されたセッションデータをレディスなどに保存します。
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