phalcon / incubator-session
Phalcon孵化器会话适配器
v2.0.0
2023-11-06 23:25 UTC
Requires
- php: >=7.4
- ext-phalcon: ^5.0
Requires (Dev)
- ext-mongodb: *
- codeception/codeception: ^4.1
- codeception/module-asserts: ^2.0
- mongodb/mongodb: ^1.16
- phalcon/ide-stubs: ^5.0
- phpstan/phpstan: ^1.10
- squizlabs/php_codesniffer: ^3.7
- vimeo/psalm: ^5.15
README
问题跟踪器
https://github.com/phalcon/incubator/issues
数据库
此适配器使用数据库后端来存储会话数据
use Phalcon\Db\Adapter\Pdo\Mysql; use Phalcon\Incubator\Session\Adapter\Database; $di->set('session', function () { // Create a connection $connection = new Mysql([ 'host' => 'localhost', 'username' => 'root', 'password' => 'secret', 'dbname' => 'test', ]); $session = new Database($connection, 'session_data'); $session->start(); return $session; });
此适配器使用以下表来存储数据
CREATE TABLE `session_data` ( `session_id` VARCHAR(35) NOT NULL, `data` text NOT NULL, `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `modified_at` TIMESTAMP NULL DEFAULT NULL, PRIMARY KEY (`session_id`) );
从phalcon/incubator 3.4升级将需要更改session_data表
ALTER TABLE session_data MODIFY COLUMN created_at TIMESTAMP DEFAULT current_timestamp() NOT NULL;
ALTER TABLE session_data MODIFY COLUMN modified_at TIMESTAMP DEFAULT NULL NULL;
Mongo
通过pecl安装PHP MongoDB扩展
pecl install mongodb
安装后,将以下行添加到您的php.ini
文件中
extension=mongodb.so
此适配器使用Mongo数据库后端来存储会话数据
use Phalcon\Incubator\Session\Adapter\Mongo as MongoSession; $di->set('session', function () { // Create a connection to mongo $mongo = new \MongoDB\Client( 'mongodb+srv://<username>:<password>@<cluster-address>/test?retryWrites=true&w=majority' ); // Passing a collection to the adapter $session = new MongoSession([ 'collection' => $mongo->test->session_data, ]); $session->start(); return $session; });