Download the PHP package kode/session without Composer

On this page you can find all versions of the php package kode/session. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package session

kode/session

高性能分布式会话管理器,支持文件、Redis、Cookie 等多种驱动,可独立使用或集成到其他框架中。

特性

安装

快速开始

基本用法

使用中间件

驱动

File 驱动

本地文件存储,适合单机部署。

Redis 驱动

分布式存储,适合多机器部署。

Redis 驱动支持两种连接方式:

Cookie 驱动

基于客户端 Cookie 存储,适合轻量级场景。

注意:Cookie 有大小限制(通常 4KB),只适合存储少量数据。

Array 驱动

纯内存存储,适合测试、CLI 与临时会话(进程结束即释放)。

Database 驱动

基于 PDO 的数据库存储,兼容 SQLite / MySQL / PostgreSQL,适合已有数据库基础设施、希望会话入库的场景。

透明加密

任意驱动均可开启透明加密,写入存储层前对值做 AES-256-GCM 加密,存储泄漏也无法还原明文。

透明压缩

任意驱动均可开启 gzip 压缩,对写入存储层的值做压缩,显著降低落库体积(文本类 / 大数组类会话尤为明显)。压缩与加密可同时开启,处理顺序为「先压缩后加密」,加密层还能进一步掩盖压缩特征。

强类型访问器

读取时按目标类型强制转换,省去手动 is_numeric / filter_var 判断:

每个方法都带类型默认值(如 getInt('x', 7)),缺失或非可转换值时返回默认值。

延迟写盘(lazy write-through)

set/delete 只更新内存与脏标记(dirty / removed),真正落盘推迟到 save()/close() 一次性批量完成,减少每个 set 触发的驱动 I/O(文件重写 / Redis 往返)。

概率化垃圾回收(GC)

中间件按概率触发 GC,避免每请求都扫描过期数据:

也可在 SessionManager 全局配置 设置 GC 默认值(中间件配置优先级更高):

或运行时动态调整:

也可手动在长周期任务中调用 $manager->gc($maxLifetime, $config) 强制回收。

驱动列表

驱动 说明 使用场景
File 本地文件存储 单机部署、开发环境
Redis 分布式存储 生产环境、多机器部署
Cookie 客户端存储 轻量级场景、简单数据
Array 内存存储 单元测试、CLI、临时会话
Database PDO 数据库存储(SQLite/MySQL/PostgreSQL) 已有数据库基础设施、会话入库

配置

SessionManager 配置

中间件配置

API 文档

Session 类

基本操作

数据存取

进阶操作

闪存数据

闪存数据只在当前请求和下一次请求中可用。

错误/成功信息

CSRF 保护

SessionManager 类

协程安全

本包不使用全局 $_SESSION,完全在内存中管理 session 数据,支持 PHP Fiber/协程。

Fiber 中的使用

请求隔离

配合 kode/context 做请求内会话隔离:

分布式和并行

分布式锁

Redis 驱动支持分布式锁:

多进程支持

框架集成

集成到自定义框架

目录结构

测试

性能提示

  1. File 驱动:适合开发环境和小规模部署
  2. Redis 驱动:生产环境推荐,支持分布式和高并发
  3. Cookie 驱动:仅用于轻量级场景,不适合存储大量数据
  4. Database 驱动:适合已有数据库基础设施、希望会话入库的场景;采用跨库 upsert 与抢占式锁
  5. 延迟写盘:批量 set/delete 只在 save() 时落盘一次,避免每个 set 触发驱动 I/O
  6. 透明加密:开启后写入为密文,加解密有少量开销,仅对敏感场景建议开启
  7. 透明压缩:对文本 / 大数组类会话可显著缩小落库体积、降低 I/O,与加密叠加时「先压缩后加密」几乎不增加额外开销
  8. GC 回收:中间件按概率触发,必要时可在长周期任务中手动调用 $manager->gc() 清理过期 session

驱动扩展

如需添加新的驱动,只需实现 Kode\Session\Contract\Driver 接口:

然后注册到 SessionManager(通过 extend() 注册的回调返回 Driver 实例,已可正确生效):

许可证

Apache License 2.0 - see LICENSE


All versions of session with dependencies

PHP Build Version
Package Version
Requires php Version >=8.3
ext-json Version *
ext-zlib Version *
kode/context Version ^3.1
psr/http-message Version ^1.0|^2.0
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package kode/session contains the following files

Loading the files please wait ...