abbadon1334 / atk4-session
php session using atk4 data handler
Installs: 7 300
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 12
Requires
- php: >=7.4 <8.2
- ext-pdo: *
- atk4/data: ~3.1.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.13
- friendsofphp/php-cs-fixer: ^3.0
- guzzlehttp/guzzle: 7.4.1
- johnkary/phpunit-speedtrap: ^3.3
- nikic/fast-route: 1.3.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.0
- phpstan/phpstan-deprecation-rules: ^1.0
- phpunit/phpunit: ^9.5.5
- symfony/console: ^4.4.30 || ^5.3.7
- symfony/process: ^5.4
- dev-master
- 3.1.0
- 2.4
- v1.1
- v1.0
- dev-renovate/mysql-9.x
- dev-renovate/guzzlehttp-guzzle-7.x
- dev-renovate/phpunit-phpunit-11.x
- dev-renovate/release-drafter-release-drafter-6.x
- dev-renovate/codecov-codecov-action-4.x
- dev-renovate/actions-cache-4.x
- dev-renovate/php-8.x
- dev-renovate/major-symfony
- dev-renovate/actions-checkout-4.x
- dev-renovate/postgres-16.x
- dev-renovate/gvenzl-oracle-xe-21.x
- dev-release/3.1
This package is auto-updated.
Last update: 2024-09-27 03:46:16 UTC
README
Session handler for Atk4\Data (@see https://github.com/atk4/data)
Install
composer require abbadon1334/atk4-session
Initialize without atk4\ui
// autoload include '../vendor/autoload.php'; // create pesistence $db = \Atk4\data\Persistence::connect('mysql://root:password@localhost/atk4'); // init session handler new \Atk4\ATK4DBSession\SessionHandler($p, [/* session options */]);
Create session table using atk4\schema
(new \Atk4\Data\Schema\Migrator(new \atk4\ATK4DBSession\SessionModel($p)))->create();
OR
Create session table with SQL query
CREATE TABLE `session` ( `id` bigint() NOT NULL AUTO_INCREMENT, `session_id` varbinary(255) DEFAULT NULL, `data` blob, `created_on` datetime(6) NULL DEFAULT NULL, `updated_on` datetime(6) NULL DEFAULT NULL, PRIMARY KEY (`id`), KEY `session_id` (`session_id`) ) ENGINE=InnoDB;
Session GC
if you use InnoDB deletes are slow, so the best option for huge request application is to set a cronjob which run every
2 minutes, you can find an example in : demos/example/cronjob.example.php
.
When you instantiate the SessionHandler, if you use the crojob, set the gc_probability option to 0 to disable automatic triggering of gc.
Why i need to replace the default PHP Session Handler with this?
Because of file locking ( here a good article about the argument link)
Every call that use sessions read a file and set a lock on it until release or output, to prevent race conditions.
It's clearly a shame to have file locking on things that are usually static, like nowadays sessions.
Using an alternative you'll have for sure race conditions, BUT what race condition can be if you, usually, have only an ID in $_SESSION and that is nearly immutable from login to logout.
SessionHandler will substitute SessionHandler class in PHP and will store session data in database using atk4\data instead of using files.
In atk4\ui where async calls are massively used, this problem is much more evident.
You can add it without breaking your project, it already works, but is still in development and need a strong review for security issue.