Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Zend Session Laravel Package

zendframework/zend-session

zendframework/zend-session provides robust session management for PHP applications, with configurable storage, session containers, validators, and save handlers. Integrates cleanly with Zend Framework components to secure and organize session data across requests.

View on GitHub
Deep Wiki
Context7

Session Save Handlers

zend-session comes with a set of save handler classes. Save handlers themselves are decoupled from PHP's save handler functions and are only implemented as a PHP save handler when utilized in conjunction with Zend\Session\SessionManager.

Cache

Zend\Session\SaveHandler\Cache allows you to provide an instance of Zend\Cache\Storage\Adapter\AdapterInterface to be utilized as a session save handler. Generally if you are utilizing the Cache save handler; you are likely using products such as memcached.

Basic usage

A basic example is one like the following:

use Zend\Cache\StorageFactory;
use Zend\Session\SaveHandler\Cache;
use Zend\Session\SessionManager;

$cache = StorageFactory::factory([
    'adapter' => [
       'name' => 'memcached',
       'options' => [
           'server' => '127.0.0.1',
       ],
    ],
]);

$saveHandler = new Cache($cache);
$manager = new SessionManager();
$manager->setSaveHandler($saveHandler);

DbTableGateway

Zend\Session\SaveHandler\DbTableGateway allows you to utilize Zend\Db\TableGateway\TableGatewayInterface implementations as a session save handler. Setup of a DbTableGateway save handler requires an instance of Zend\Db\TableGateway\TableGatewayInterface and an instance of Zend\Session\SaveHandler\DbTableGatewayOptions. In the most basic setup, a TableGateway object and using the defaults of the DbTableGatewayOptions will provide you with what you need.

Creating the database table

CREATE TABLE `session` (
    `id` char(32),
    `name` char(32),
    `modified` int,
    `lifetime` int,
    `data` text,
     PRIMARY KEY (`id`, `name`)
);

Basic usage

use Zend\Db\TableGateway\TableGateway;
use Zend\Session\SaveHandler\DbTableGateway;
use Zend\Session\SaveHandler\DbTableGatewayOptions;
use Zend\Session\SessionManager;

$tableGateway = new TableGateway('session', $adapter);
$saveHandler  = new DbTableGateway($tableGateway, new DbTableGatewayOptions());
$manager      = new SessionManager();
$manager->setSaveHandler($saveHandler);

MongoDB

Zend\Session\SaveHandler\MongoDB allows you to provide a MongoDB collection to be utilized as a session save handler. You provide the options in the Zend\Session\SaveHandler\MongoDBOptions class. You must install the mongodb PHP extensions and the MongoDB PHP library.

Basic Usage

use MongoDB\Client;
use Zend\Session\SaveHandler\MongoDB;
use Zend\Session\SaveHandler\MongoDBOptions;
use Zend\Session\SessionManager;

$mongoClient = new Client();
$options = new MongoDBOptions([
    'database'   => 'myapp',
    'collection' => 'sessions',
]);
$saveHandler = new MongoDB($mongoClient, $options);
$manager     = new SessionManager();
$manager->setSaveHandler($saveHandler);

Custom Save Handlers

There may be cases where you want to create a save handler. Creating a custom save handler is much like creating a custom PHP save handler, with minor differences. All zend-session-compatible save handlers must implement Zend\Session\SaveHandler\SaveHandlerInterface. Additionally, if your save handler has configurable functionality, you will also need to create an options class.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport