Recommend this page to a friend! |
Download |
Info | Documentation | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not yet rated by the users | Total: 64 | All time: 10,406 This week: 660 |
Version | License | PHP version | Categories | |||
php-react-http-sessi 1.0 | Custom (specified... | 7 | User Management, Cache, PHP 7 |
Middleware for implementing PHP Sessions in ReactPHP Http Server.
Via composer:
composer require niko9911/react-http-middleware-session
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();
}
]
);
Licensed under the MIT license.
Files (11) |
File | Role | Description | ||
---|---|---|---|---|
scripts (1 file) | ||||
src (1 file, 1 directory) | ||||
.php_cs.dist | Example | Example script | ||
composer.json | Data | Auxiliary data | ||
composer.lock | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
phpunit.xml.dist | Data | Auxiliary data | ||
README.md | Doc. | Read me |
Files (11) | / | src |
File | Role | Description | ||
---|---|---|---|---|
Session (2 files, 1 directory) | ||||
SessionMiddleware.php | Class | Class source |
Files (11) | / | src | / | Session |
File | Role | Description | ||
---|---|---|---|---|
Id (1 file) | ||||
Id.php | Class | Class source | ||
Session.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 |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.