gbeushausen/ silex-dynamodb-session-provider
适用于Silex 2.x的Amazon DynamoDB会话提供者
2.0.1
2018-01-13 08:38 UTC
Requires
- php: >=5.5.9
- aws/aws-sdk-php: >=3.19
- silex/silex: ~2.0
This package is auto-updated.
Last update: 2024-09-14 07:27:37 UTC
README
为Silex 2.x项目提供存储在Amazon DynamoDB上的会话支持。
通常PHP会话不可扩展。一旦涉及到负载均衡/多服务器设置,就需要寻找更好的解决方案。Amazon的DynamoDB NoSQL存储引擎是解决此问题的快速、简单且可扩展的解决方案。
只需将其实现到您的项目中(见下文)。您还需要一个解决方案来清除表中的陈旧会话。由于删除许多旧会话可能需要大量的写入容量单元,最好配置一个cron作业并在夜间运行垃圾收集器。
Gunnar Beushausen
https://www.gunnar-beushausen.de
基本用法
use Silex\Provider\SessionServiceProvider;
use DynamoDbSession\DynamoDbSessionServiceProvider;
//Don't keep your AWS credentials in your source code! Put it in an environment variable,
//or if you're hosting on EC2, use IAM Roles!
$this->application['AwsSdk'] = function() {
return new Sdk([
'region' => 'eu-west-1', // EU West (Ireland) Region
'version' => 'latest' // Use the latest version of the AWS SDK for PHP
]);
};
$app['session.storage.options'] = [
'cookie_httponly' => true,
'hash_function' => 'sha256',
'hash_bits_per_character' => 6,
];
$app['session.dynamodb.options'] = [
'table_name' => 'sessions',
];
$app->register(new SessionServiceProvider());
$app->register(new DynamoDbSessionServiceProvider());
//To run the Garbage Collector in order to remove stale and old sessions from the table, run the following code:
$app['session.dynamodb.garbagecollect'];