phalcon / incubator-session
Phalcon Incubator Sessions Adapters
Fund package maintenance!
phalcon
Open Collective
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
Issues tracker
https://github.com/phalcon/incubator/issues
Database
This adapter uses a database backend to store session data:
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; });
This adapter uses the following table to store the data:
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`) );
Upgrading from phalcon/incubator 3.4 will require changes to the session_data table:
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
Install PHP MongoDB Extension via pecl:
pecl install mongodb
After install, add the following line to your php.ini
file:
extension=mongodb.so
This adapter uses a Mongo database backend to store session data:
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; });