koded/session
Composer 安装命令:
composer require koded/session
包简介
A session library with custom handlers and php.ini support
README 文档
README
The library relies on the php.ini settings.
Every session ini directive can be reset with the
Koded\Session\SessionConfiguration object.
Refer to php.ini session directives: http://php.net/manual/en/session.security.ini.php
Usage
The session is started automatically by using one of the 2 methods:
app configuration
[
'session' => [
// your ini "session." overwrites, without "session." prefix
]
]
or using a SessionMiddleware
include this middleware class in your middleware stack
// your middleware stack $middleware = [ SessionMiddleware::class ];
Session class and function
session()->get('key'); session()->set('key', 'value'); // etc.
The session class can be instantiated and used, but the function session()
is recommended instead an instance of Session class.
Handlers Configuration
The bare minimum is to define the handler you want to use for the session:
// in your configuration file return [ 'session' => [ 'save_handler' => 'redis | memcache' ] ]
If you do not choose one of the Redis or Memcached, it defaults to files
handler which is the PHP's default session mechanism.
However, the files handler might not be desirable if your application
runs in Docker, Kubernetes, distributed environment, etc.
The best choice for PHP sessions is Redis in almost all situations.
WARNING: Memcached may drop the session data, because it's nature. Use it with caution!
Redis handler
[
'session' => [
'save_handler' => 'redis'
// OPTIONAL, these are the defaults
'host' => 'localhost',
'port' => 6379,
'timeout' => 0.0,
'retry' => 0,
'db' => 0,
'prefix' => 'sess:',
'serializer' => 'php', // or "json"
'binary' => false, // TRUE for igbinary
]
]
A typical Redis settings:
- 1 server
- application + redis on the same machine
- Redis (127.0.0.1:6379)
- no auth (Redis is not available from outside)
[
'session' => [
'save_handler' => 'redis',
'name' => 'session-name',
'prefix' => 'sess:',
// isolate the session data in other db
'db' => 1
]
]
To support huge volumes you need a good sysadmin skills and wast knowledge to set the Redis server(s).
Memcached handler
[
'session' => [
'save_handler' => 'memcached',
// OPTIONAL: defaults to ['127.0.0.1', 11211]
// If you have multiple memcached servers
'servers' => [
['127.0.0.1', 11211],
['127.0.0.1', 11212],
['127.0.0.2']
...
],
// OPTIONAL: the options are not mandatory
'options' => [
...
]
]
]
A typical Memcached settings:
- 1 server
- application + memcached on the same machine
- Memcached (127.0.0.1:11211)
[
'session' => [
'save_handler' => 'memcached',
'name' => 'session-name',
'prefix' => 'sess.'
]
]
To support huge amount of users you need a decent amounts of RAM on your servers. But Memcached is a master technology for this, so you should be fine.
Files handler
This one is not recommended for any serious business. It's fine only for small projects.
All session directives are copied from php.ini.
[
'session' => [
// OPTIONAL: defaults to "session_save_path()"
// the path where to store the session data
'save_path' => '/var/www/sessions',
'serialize_handler' => 'php'
]
]
A typical native PHP session settings:
[
'session' => [
// really nothing,
// skip this section in your configuration
]
]
You cannot use this handler if you've scaled your application, because the session data will most likely be handled randomly on a different instance for every HTTP request.
koded/session 适用场景与选型建议
koded/session 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 314 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 09 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「redis」 「memcached」 「session」 「session-handler」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 koded/session 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 koded/session 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 koded/session 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memcached Bundle
Simple to use mutex implementation that can use flock, memcache, memcached, mysql or redis for locking
Secure session middleware for Slim 3 framework
A Symfony bundle for Mutex implementation for PHP
Microservice RPC through message queues.
Graphic stand-alone administration for memcached to monitor and debug purpose
统计信息
- 总下载量: 314
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 14
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2018-09-23