lboynton/memcached-json-session-save-handler

此包已被废弃,不再维护。没有推荐替代包。

用于在memcache中存储会话的JSON格式会话保存处理器。它使用php-memcached扩展。

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

一个JSON格式的memcached会话保存处理器。默认情况下,在php-memcached扩展中通过memcached保存会话时,序列化由php、php_igbinary或WDDX执行。此自定义会话保存处理器将会话序列化为JSON并存储在memcached中。

安装

使用 composer 将保存处理器包含到您的应用程序中。

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

使用

// 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';