romeoz/rock-session

A simple Session library for PHP

0.12.0 2015-11-09 06:05 UTC

This package is not auto-updated.

Last update: 2024-11-19 05:28:59 UTC


README

Latest Stable Version Total Downloads Build Status HHVM Status Coverage Status License

Handlers

Installation

From the Command Line:

composer require romeoz/rock-session

or in your composer.json:

{
 "require": {
     "romeoz/rock-session": "*"
 }
}

Quick Start

####Session as key-value memory storage

$config = [
    'cache' => new \rock\cache\Memcached
];
$session = new \rock\session\MemorySession($config);
$session->add('name', 'Tom');

echo $session->get('name'); // result: Tom

####Session as MongoDB storage

$config = [
    'connection' => new \rock\mongodb\Connection
];
$session = new \rock\session\MongoSession($config);
$session->add('name', 'Tom');

echo $session->get('name'); // result: Tom

Default is used the garbage collector (GC). You can use TTL indexes.

$connection = new \rock\mongodb\Connection;

// Create TTL index
$connection
    ->getCollection('session')
    ->createIndex('expire', ['expireAfterSeconds' => 0]);

$config = [
    'connection' => $connection,
    'useGC' => false
];
$session = new \rock\session\MongoSession($config);
$session->add('name', 'Tom');

echo $session->get('name'); // result: Tom

Requirements

  • PHP 5.4+
  • For MemorySession required Rock Cache: composer require romeoz/rock-cache
  • For MongoSession required Rock MongoDB: composer require romeoz/rock-mongodb
  • For DbSession required Rock DB: composer require romeoz/rock-db

All unbolded dependencies is optional.

License

Session library is open-sourced software licensed under the MIT license.