drbiko/dynamodb-sessions-dependency-free 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

drbiko/dynamodb-sessions-dependency-free

Composer 安装命令:

composer require drbiko/dynamodb-sessions-dependency-free

包简介

An implementation of a session handler for storing sessions in AWS's DynamoDB, but with no dependencies on the AWS SDK, Guzzle etc

README 文档

README

Idealstack - the best way to run PHP on AWS

dynamodb-sessions-dependency-free

An implementation of a session handler for storing sessions in dynamoDB, but with no dependencies on the AWS SDK, Guzzle etc. As a bonus it's also faster!

The Idealstack AWS hosting platform uses this to provide transparent support for DynamoDB sessions, so users don't need to change anything in their code.

See our blog post about it for instructions on how to use it, setup the required tables etc

Features

  • Essentially a drop-in replacement for the official session handler in the AWS SDK
  • Dependency-free - does not depend on any other composer packages. Only requires the core curl and json extensions be enabled in PHP
  • Does not require an autoloader (although will work fine with one, eg composer)
  • Supports most common AWS authentication methods (eg instance profiles, ECS task roles, .aws config files, environment variables)
  • Compatible with all major PHP versions (even PHP 5.6, for all you luddites out there)
  • Does not support locking (that's just because we don't need it, a PR is welcome or raise an issue if you need it)

Why do you want this?

Possibly you don't. The AWS SDK includes a session handler that is maintained by AWS and might be a better choice for most people.

Why do you want to store sessions in dynamodb? If you are running PHP in a clustered environment the default file-based session handler won't work.

You can store sessions in an SQL database, or Redis, but in many ways dynamodb is a better choice on AWS. It automatically scales to any number of reads/writes, can be distributed globally, has an elastic pricing model that is cheaper for small sites etc etc.

Here's a couple of reasons why you might want to use this code over the AWS SDK:

  • If you aren't using the AWS SDK for other things, the session handler is going to include a large number of PHP classes on every page load that aren't needed. This potentially slows things down, uses more RAM, IO and Opcache etc
  • It's faster. About 30% faster. We're talking about the difference between 30ms and 20ms here, so it's unlikely that sessions are the bottleneck slowing your app down. Still, faster is always good.
  • If you choose to include this automatically using php's auto_prepend_file - you can get funny side-effects if you use the AWS SDK version. It requires an autoloader, which can mess with your project's own autoloading. Also it 'pollutes' the namespace. If your code uses a different version of the SDK from the one the sessions use, you should expect problems. This is the reason why we developed this for Idealstack as we make dynamodb sessions transparent to our users code.

Installation

via composer

composer require idealstack/dynamodb-sessions-dependency-free

or clone this repository

How to use it

Configuration is the same as the AWS SDK version, so read their docs:

https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/service_dynamodb-session-handler.html

You configure the DynamoDB table the same as the AWS SDK docs recommend. However we'd suggest you also use the DynamoDB 'ttl' capability to garbage collect your sessions. Set that on the 'expires' field (this also works with the native SDK). See the notes in our blog post about how to setup the table.

use Idealstack\DynamoDbSessionHandlerDependencyFree;
// or if you don't want to use composer auto-loader, try: 
// require(__DIR__ .'/vendor/idealstack/dynamodb-session-handler-dependency-free/src/DynamoDbSessionHandler.php');

(new Idealstack\DynamoDbSessionsDependencyFree\DynamoDbSessionHandler(
[
            'table_name' => 'your-session-table-name',
            'region'     => 'local',
            'endpoint'   => 'http://localhost:8000',
// Credentials.  In production we recomend you use an instance role so you do not need to hardcode these.
// At least make sure you don't hardcode them and commit them to github!
            'credentials' => [
                'key' => 'AAAAAAAAAAAAAAAAAAAAAA',
                'secret' => 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'
            ],
// These are all defaults. 
//             // Base64 encode data when reading and writing. Avoids problems with binary data,  Note this is 
//             // not the behaviour of the AWS SDK, so set to false if you require compatibility with existing
//             // sessions  created with the SDK
//            'base64' => true, 
//            'hash_key' => 'id',
//
//            // The lifetime of an inactive session before it should be garbage collected. If it isn't provided, 
//            // the actual lifetime value that will be used is ini_get('session.gc_maxlifetime').
//            'session_lifetime' => 86400, // 24 hours
//            'consistent_reads' => true, //You almost certainly want this to be true
//            'session_locking' => false, //True is not supported
        ]

))->register();

drbiko/dynamodb-sessions-dependency-free 适用场景与选型建议

drbiko/dynamodb-sessions-dependency-free 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.82k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 05 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「amazon」 「sdk」 「cloud」 「aws」 「dynamodb」 「sessions」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 drbiko/dynamodb-sessions-dependency-free 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 drbiko/dynamodb-sessions-dependency-free 我们能提供哪些服务?
定制开发 / 二次开发

基于 drbiko/dynamodb-sessions-dependency-free 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.82k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2019-05-19