PHP code example of lboynton / memcached-json-session-save-handler

1. Go to this page and download the library: Download lboynton/memcached-json-session-save-handler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lboynton / memcached-json-session-save-handler example snippets


// set up autoloading using composer
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';