DynamoDB for PHP Sessions

We are currently using NAS session file storage to store PHP for an array of load-balanced, scalable application servers.

We are interested in replacing this with a more reliable solution, and Amazon's DynamoDB looks interesting. Here I see one possible problem:

http://thwartedefforts.org/2006/11/11/race-conditions-with-ajax-and-php-sessions/

I suspect DynamoDB does not support locking objects. Any workarounds you might think of?

If you have experience working with other NoSQL systems used for PHP sessions, you can also log in freely, as training might be similar.

Thanks in advance

+6
source share
4 answers

Using DynamoDB conditional records, you can implement a pessimistic locking scheme similar to how the default PHP session handler works.

Someone else requested a DynamoDB session handler: https://forums.aws.amazon.com/thread.jspa?messageID=328060 .

Updated: The AWS SDK for PHP now has a session handler for DynamoDB. See https://github.com/amazonwebservices/aws-sdk-for-php/blob/master/extensions/dynamodbsessionhandler.class.php and http://docs.amazonwebservices.com/AWSSDKforPHP/latest/#i=DynamoDBSessionHandler

Updated: There is an article on the AWS blog about the DynamoDB session handler: http://aws.typepad.com/aws/2012/04/scalable-session-handling-in-php-using-amazon-dynamodb.html

+8
source

An interesting idea (+1) - and a well-thought-out article really, just removed it for now;)

As for the other NoSQL options for storing PHP sessions, you can check out MongoSession, the MongoDB PHP session handler that lists the race conditions for Ajax and PHP sessions , and seems to address documented issues at the same time:

I recently updated the library to support atomic operations on both session records and garbage collection to prevent this race condition.

A similar approach should be possible with Amazon DynamoDB , as well as using the appropriate combination of conditional updates, atomic counters, and sequential readings, see Details on these concepts and / or an introduction to the following frequently asked questions:

+2
source

Are your servers on AWS? Why don't you try the ElastCache feature? http://aws.amazon.com/en/elasticache/

I use CakePHP, witch supports DB and Memcache for storing sessions. After some time learning, I chose Memcache. In fact, I install PHP to store sessions in Memcache and install CakePHP to use the php session configuration. This way I can separate my memcache instances for sessions and caching.

Sincerely.

+1
source
+1
source

Source: https://habr.com/ru/post/906838/


All Articles