I’m trying to use custom session handler using Google Datastore. There is a part of code of main module:
public function onBootstrap(MvcEvent $e)
{
$sessionConfig = new SessionConfig();
$sessionManager = new SessionManager($sessionConfig);
$sessionConfig->setOptions(
$e->getApplication()->getServiceManager()->get('Config')['datastore-session']['session']
);
$sessionsStorage = $e->getApplication()->getServiceManager()->get('CustomSessionStorage\Storage\CustomStorage');
$sessionManager->setSaveHandler($sessionsStorage->createHandler());
$sessionManager->start();
Container::setDefaultManager($sessionManager);
}
But it doesn’t work. Sessions are still using files on server and method “SessionHandlerInterface::open” is never called.
But when I write this code (in the same place onBootstrap), session handler is used and methods “open”, “read” etc is used. Why the first code doesn’t work?
session_write_close();
session_set_save_handler($sessionsStorage->createHandler(), true);
session_save_path('sessions');
session_start();
How to use my custom handler?