Question

we are currently using a NAS for PHP session files storage for an array of autoscaling load balanced app servers.

We are interested to replace this with a more robust solution and DynamoDB from Amazon looks interesting. I see one possible issue here, documented here:

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

I suspect DynamoDB does not support object locking. Any workarounds you can think of?

If you have any experience from other NoSQL systems used for PHP sessions also feel free to jump in as the learnings might be similar.

Thanks in advance

Was it helpful?

Solution

Using DynamoDB's conditional writes, you could implement a pessimistic locking scheme similar to the way PHP's default session handler works.

Someone else has also made a request for a DynamoDB session handler: https://forums.aws.amazon.com/thread.jspa?messageID=328060.

Updated: The AWS SDK for PHP now includes 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 about the DynamoDB session handler on the AWS blog: http://aws.typepad.com/aws/2012/04/scalable-session-handling-in-php-using-amazon-dynamodb.html

OTHER TIPS

Interesting idea (+1) - and an elaborate article indeed, just skimmed it for now though ;)

Regarding other NoSQL options for PHP session storage you might want to check out MongoSession – A PHP MongoDB Session Handler, which references Race Conditions with Ajax and PHP Sessions as well and seems to address the documented issues in the meantime:

I have recently updated the library to support atomic operations on both session writes and garbage collection to help prevent these race conditions.

A similar approach should be possible with Amazon DynamoDB as well by means of an appropriate combination of Conditional Updates, Atomic Counters and Consistent Reads, see Working with Items in Amazon DynamoDB for details on those concepts and/or check out the following FAQ entries:

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

I use CakePHP, witch supports DB and Memcache to store sessions. After some some time studding both, I've opted for Memcache. Actually, I set PHP to store sessions on Memcache and set CakePHP to use php sessions config. This way I can separate my memcache instances for sessions and caching.

Regards.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top