lboynton / memcached-json-session-save-handler
A session save handler for storing sessions in JSON format in memcache. It uses the php-memcached extension.
Installs: 1 356
Dependents: 1
Suggesters: 1
Security: 0
Stars: 13
Watchers: 6
Forks: 8
Open Issues: 0
Requires
- php: >=5.3.0
- ext-memcached: *
This package is not auto-updated.
Last update: 2021-11-02 17:19:35 UTC
README
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';