之前 google 了一些文章
作法就是把 session 存在 DynamoDB
後來發現官方已有做好的 sdk SessionHandler
https://docs.aws.amazon.com/aws-sdk-php/v3/guide/service/dynamodb-session-handler.html
也找到一篇範例
http://aws.mannem.me/?p=1020
#aws
#php
使用上也算方便
簡單範例:
<?php
ini_set("display_errors", "On"); // 顯示錯誤是否打開( On=開, Off=關 )
error_reporting(E_ALL & ~E_NOTICE);
require 'vendor/autoload.php';
use Aws\Credentials\CredentialProvider;
use Aws\DynamoDb\SessionHandler;
$sdk = new Aws\Sdk([
'region' => 'ap-northeast-1',
'version' => 'latest',
'http' => [
'debug' => true
]
]);
$dynamoDb = $sdk->createDynamoDb();
$sessionHandler = SessionHandler::fromClient($dynamoDb, [
'table_name' => 'sessions'
]);
$sessionHandler->register();
// Start the session
session_start();
// Alter the session data
// $_SESSION['user.name'] = 'xxxx';
// $_SESSION['user.role'] = 'admin';
// Close the session (optional, but recommended)
// session_write_close();
echo "successfully connected";
沒有留言:
張貼留言