PHP Classes

React PHP Session Middleware using Redis: Store session data in Redis using React PHP

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 64 All time: 10,406 This week: 660Up
Version License PHP version Categories
php-react-http-sessi 1.0Custom (specified...7User Management, Cache, PHP 7
Description 

Author

This package can be used to store session data in Redis using React PHP.

It provides session storage class that can used Redis to store session data.

The class can also provide additional information like if the current user session is active, begin a session if it was not active and getthe current session identifier.

Innovation Award
PHP Programming Innovation award nominee
March 2019
Number 3
React PHP is a project that provides event-driven programming to any PHP application somewhat similar to what React.js provides for developing user interfaces for Web based applications.

This package provides means to store PHP session data is Redis database using React PHP.

Manuel Lemos
Picture of Niko
  Performance   Level  
Name: Niko <contact>
Classes: 8 packages by
Country: Finland Finland
Age: ???
All time rank: 29166 in Finland Finland
Week rank: 200 Up1 in Finland Finland Up
Innovation award
Innovation award
Nominee: 5x

Winner: 1x

Documentation

ReactPHP Session Middleware

Middleware for implementing PHP Sessions in ReactPHP Http Server.

Install

Via composer:

composer require niko9911/react-http-middleware-session

Usage

Register middleware as you normally do. Pass cookie name to use. Pass implementation of React cache or use bridge for PSR cache.

Example:

<?php
declare(strict_types=1);

// Cache must be persisted. Array cache will not work.
// Just abstract Example. You need to implement
// \React\Cache\CacheInterface::class interface.
use Niko9911\Harold\Core\Http\Application\Middleware\SessionMiddleware;$cache = new \React\Cache\ArrayCache();

// Or
// This is just example here. I personally use PSR 
// implementation with bridge and I save all to Redis.
// This will be much easier if using redis other than
// just ReactPHP stuff. You need to require additional package.
// https://packagist.org/packages/niko9911/react-psr-cache-bridge
// https://packagist.org/packages/cache/redis-adapter
$redis = new \Redis();
$redis->connect($host, 6379);
$redis->select(0);
$redis = \Cache\Adapter\Redis\RedisCachePool($redis);
$cache = new \Niko9911\React\Cache\Bridge\ReactPsrCacheBridge($redis);

$session = new \Niko9911\React\Middleware\SessionMiddleware(
    'PHPSESS',
    $cache,
    3600,
    '/',
    '',
    false,
    false,
    new \Niko9911\React\Middleware\Session\Id\Random()
);

new \React\Http\Server(
    [
        $session,
        function (\Psr\Http\Message\ServerRequestInterface $request) {
            / @var \Niko9911\React\Middleware\Session\Session $session */
            $session = $request->getAttribute(SessionMiddleware::ATTRIBUTE_NAME);
            
            if (!$session->isActive())
            {
                 $session->begin();
            }
            
            echo $session->getId();
            
            return new \React\Http\Response();
        }
    ]
);

License

Licensed under the MIT license.


  Files folder image Files (11)  
File Role Description
Files folder imagescripts (1 file)
Files folder imagesrc (1 file, 1 directory)
Accessible without login Plain text file .php_cs.dist Example Example script
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Read me

  Files folder image Files (11)  /  scripts  
File Role Description
  Accessible without login Plain text file composer.sh Data Auxiliary data

  Files folder image Files (11)  /  src  
File Role Description
Files folder imageSession (2 files, 1 directory)
  Plain text file SessionMiddleware.php Class Class source

  Files folder image Files (11)  /  src  /  Session  
File Role Description
Files folder imageId (1 file)
  Plain text file Id.php Class Class source
  Plain text file Session.php Class Class source

  Files folder image Files (11)  /  src  /  Session  /  Id  
File Role Description
  Plain text file Random.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:64
This week:0
All time:10,406
This week:660Up