As mentioned in the Session Configuration section, setting up asynchronous PHP sessions with LightMVC is a matter of adding the appropriate configuration in the config/session.config.php file. But, one might need to use an asynchronous session in a customized way. To do so, it is necessary to instantiate a session Config object, constructor injecting into it any custom configuration array that might be deemed necessary, and obtaining an instance of the SessionManager object by requesting it through the getSessionManager() static method. Once this is done, it is a question of invoking the SessionManager’s start() method to get the session started. Here is a working example:


As of LightMVC 5.0.0, the DoctrineCommonCache namespace is replaced with the AscmvcSessionCommonCache namespace. Please update your session.config.php configuration file accordingly.


$config['session'] = [
    'enabled' => true,
    'psr6_cache_pool' => \Ascmvc\Session\Cache\DoctrineCacheItemPool::class,
    'doctrine_cache_driver' => \Ascmvc\Session\Common\Cache\FilesystemCache::class,
    'doctrine_filesystem_cache_directory' => __DIR__ . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR,
    'session_name' => 'MYSESSION',
    'session_path' => '/',
    'session_domain' => 'localdomain.local',
    'session_secure' => false,
    'session_httponly' => false,
    'session_id_length' => 32,
    'session_id_type' => 1, // 1 = alphanumeric, 2 = digits only
    'session_storage_prefix' => 'ascmvc',
    'session_token_regeneration' => 60 * 30, // 30 minutes - session token will change after 30 minutes
    'session_expire' => 60 * 60, // 60 minutes - session will expire after 60 minutes of inactivity

$config = new \Ascmvc\Session\Config($config['session']);
$sessionManager = \Ascmvc\Session\SessionManager::getSessionManager(null, null, $config);

try {
} catch (\Throwable $e){
    echo $e->getMessage();

// Do something here! :)

// Manually persist the session data.
// This step is optional, as the session object will persist itself automatically
// before the PHP script exits and falls out of scope of the PHP runtime.