Download .zip |
Info | Documentation | View files (20) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2019-08-26 (11 days ago) | Not yet rated by the users | Total: 1 This week: 1 | All time: 9,701 This week: 293 |
Version | License | PHP version | Categories | |||
atk4-session 1.0 | MIT/X Consortium ... | 5 | PHP 5, User Management |
Description | Author | |
This package can be used to store and retrieve PHP session data in a database. |
|
Session handler for atk4\data\Persistence (@see https://github.com/atk4/data)
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);
initialize with atk4\ui in App::init method
$this->add(new AppSessionHandler());
Create session table using atk4\schema
(new \atk4\schema\Migration\MySQL(new \atk4\ATK4DBSession\SessionModel($p)))->migrate();
OR
Create session table with SQL query
CREATE TABLE `session` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`session_id` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`data` text COLLATE utf8_unicode_ci,
`created_on` timestamp NULL DEFAULT NULL,
`updated_on` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `session_id` (`session_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
/
* SessionHandler constructor.
*
* @param \atk4\data\Persistence $p atk4 data persistence
* @param int $gc_maxlifetime seconds until session expire
* @param float $gc_probability probability of gc for expired sessions
* @param array $php_session_options options for session_start
*/
public function __construct($p, $gc_maxlifetime = null, $gc_probability = null, $php_session_options = [])
max session lifetime before eligible to gc, default value is set to 60 * 60 secods = 1 hour
percentage of probability of gc expired sessions, default is set to 1/1000 request. You have to consider few things for tweaking this value, because it must be sized to your project
if you use InnoDB deletes are slow and if set it low too many calls will have a little delay, if you set too high few calls will have a huge delay.
Considering disable it setting this value to false and use an alternative method like cronJob with frequency /2 * that calls code like example : demos/cronjob.php
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.
Files |
File | Role | Description | ||
---|---|---|---|---|
demos (2 files) | ||||
src (3 files) | ||||
tests (3 files, 1 directory) | ||||
.codeclimate.yml | Data | Auxiliary data | ||
.php_cs.dist | Example | Example script | ||
.styleci.yml | Data | Auxiliary data | ||
.travis.yml | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
phpunit.xml | Data | Auxiliary data | ||
README.md | Doc. | Documentation | ||
renovate.json | Data | Auxiliary data |
Files | / | demos |
File | Role | Description |
---|---|---|
cronjob.php | Example | Example script |
test.php | Example | Example script |
Files | / | src |
File | Role | Description |
---|---|---|
AppSessionHandler.php | Class | Class source |
SessionHandler.php | Class | Class source |
SessionModel.php | Class | Class source |
Files | / | tests |
File | Role | Description | ||
---|---|---|---|---|
SessionTraits (3 files) | ||||
SessionHandlerCallTracer.php | Class | Class source | ||
SessionHandlerTest.php | Class | Class source | ||
webserver.php | Example | Example script |
Files | / | tests | / | SessionTraits |
File | Role | Description |
---|---|---|
traitBackgroundProcess.php | Class | Class source |
traitNeededFiles.php | Class | Class source |
traitPhpServerProcess.php | Class | Class source |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.