lboynton/memcached-json-session-save-handler

This package is abandoned and no longer maintained. No replacement package was suggested.

A session save handler for storing sessions in JSON format in memcache. It uses the php-memcached extension.

0.0.1 2013-03-12 20:32 UTC

This package is not auto-updated.

Last update: 2021-11-02 17:19:35 UTC


README

Build Status

A JSON-formatted memcached session save handler. By default, when saving sessions in memcached using the php-memcached extension, serialisation is performed by either php, php_igbinary or WDDX. This custom session save handler serialises the session as JSON and stores it in memcached.

Installation

Use composer to include the save handler in your application.

{
    "require": {
        "lboynton/memcached-json-session-save-handler": "0.0.1"
    }
}

Usage

// set up autoloading using composer
require 'vendor/autoload.php';

// create connection to memcached
$memcached = new Memcached();
$memcached->addServer('localhost', 11211);

// register handler (PHP 5.3 compatible)
$handler = new Lboy\Session\SaveHandler\Memcached($memcached);

session_set_save_handler(
    array($handler, 'open'),    
    array($handler, 'close'),
    array($handler, 'read'),
    array($handler, 'write'),
    array($handler, 'destroy'),
    array($handler, 'gc')
);

// the following prevents unexpected effects when using objects as save handlers
register_shutdown_function('session_write_close');

session_start();

// start using the session
$_SESSION['serialisation'] = 'should be in json';