mintyphp/session-handlers
Composer 安装命令:
composer require mintyphp/session-handlers
包简介
Better session handlers
README 文档
README
This repository contains a set of PHP session save handlers that support locking. I also contains a test suite to prove that they do. Current handlers that can be tested (and their corresponding test mode) are:
- standard
- default (SessionHandler)
Uses the "files" session module (PHP built-in). - memcachedn (NativeMemcachedSessionHandler)
Uses the "memcached" session module (ext-memcached). - redisn (NativeRedisSessionHandler)
Uses the "redis" session module (ext-redis).
- default (SessionHandler)
- strict (docs / rfc)
- files (FilesSessionHandler)
Locks using ".lock" files instead of "flock" calls. - memcached (MemcachedSessionHandler)
Locks using Memcache's atomic "add" operation. - redis (RedisSessionHandler)
Locks using Redis' atomic "setNx" operation.
- files (FilesSessionHandler)
Note that the standard mode testable handlers implement strict mode as well, but can't be tested as strict handlers.
Requirements
You can install the dependencies of this script using:
sudo apt install php-cli php-curl
Optional dependencies can be installed using:
sudo apt install memcached php-memcached redis php-redis
You need PHP 7.4 or higher to run the code.
Using the handlers
This package is on Packagist and can be installed using Composer, using:
composer require mintyphp/session-handlers
You can use the Redis handler by adding these two lines to your PHP code:
ini_set('session.save_path', 'tcp://localhost:6379');
ini_set('session.use_strict_mode', true);
session_set_save_handler(new RedisSessionHandler(), true);
Note that these lines must be executed before the "session_start()" call.
Running the tests
You can run the tests from the command line using:
php run-tests.php
The code will execute in about 1 second per handler and test 104 HTTP calls for each handler. The following output means that the tests succeeded:
standard - default : OK
standard - memcachedn : OK
standard - redisn : OK
strict - files : OK
strict - memcached : OK
strict - redis : OK
The word "FAILED" appears on a failed test and "SKIPPED" is shown when the PHP module is not loaded for either Redis or Memcache.
Stress testing
Use this for 100 runs:
for i in `seq 1 100`; do php run-tests.php silent; done
As shown, you may use the argument "silent" to suppress output on successful or skipped tests.
Links to other locking handlers
Below you find a few other implementations of locking Session handlers:
- https://github.com/mevdschee/symfony-session-tests (Symfony "files")
- https://github.com/stechstudio/laravel-raw-sessions (Laravel "files")
- https://github.com/1ma/RedisSessionHandler (Redis)
- https://github.com/colinmollenhour/php-redis-session-abstract (Redis)
- https://github.com/kronostechnologies/redis-session-handler (Redis)
Enjoy!
mintyphp/session-handlers 适用场景与选型建议
mintyphp/session-handlers 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.81k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 12 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mintyphp/session-handlers 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mintyphp/session-handlers 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.81k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-09