DynamoDB for PHP sessions

  • 5,320 views
Uploaded on

Step by step how-to for setting up amazon's dynamoDB as backend for storing PHP sessions. Presented at Greece's AWS Usergroup meetup.

Step by step how-to for setting up amazon's dynamoDB as backend for storing PHP sessions. Presented at Greece's AWS Usergroup meetup.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
5,320
On Slideshare
0
From Embeds
0
Number of Embeds
3

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. DynamoDB for PHP Session Storage 25 April 2012 Andreas Chatzakis @achatzakis on twitter AWSUG Greece Not affiliated with, sponsored or endorsed by AWS
  • 2. Sessions in the cloudSticky sessions?Memcache?MySQL?Redis?Enter DynamoDB:Highly available – Consistently performingPersistentAWS SDK now includes drop in PHP sessionhandler replacement 2
  • 3. Create a user 3
  • 4. Create a table 4
  • 5. Give Permissions{ "Statement": [ { "Sid": "Stmt1335183103764", "Action": [ "dynamodb:BatchGetItem", "dynamodb:DeleteItem", "dynamodb:DescribeTable", "dynamodb:GetItem", "dynamodb:PutItem", "dynamodb:Query", "dynamodb:Scan", "dynamodb:UpdateItem" ], "Effect": "Allow", "Resource": [ "arn:aws:dynamodb:us-east-1:846544612030:table/php-sessions-test"] } ] } 5
  • 6. Install & Configure SDKInstall the latest version of the SDK on your web serverimage - http://aws.amazon.com/sdkforphp/ Update config.inc.php with the credentials of the user we created in step 1 the default-cache-config parameter (we went for apc, as it is already running on our instances.) any other parameters depending on your specific setup details (the file is well documented) 6
  • 7. Instantiaterequire_once /path-to/AWSSDKforPHP/sdk.class.php;// Instantiate the Amazon DynamoDB client.$dynamodb = new AmazonDynamoDB();$dynamodb->set_hostname("https://dynamodb.us-east-1.amazonaws.com");// Register the DynamoDB Session Handler.$handler = $dynamodb->register_session_handler(array( table_name => php-sessions-test, hash_key => id, session_lifetime => 0, consistent_reads => true, session_locking => false, max_lock_wait_time => 15, min_lock_retry_utime => 5000, max_lock_retry_utime => 50000,)); 7
  • 8. Update php.inisession.save_handler = userauto_prepend_file = /path-to/dynamosessions.php Restart web server Test Snapshot fresh AMI 8
  • 9. ConsiderationsEstimate read/write throughput requirements Validate post go liveDoes your application need locking? By defaultphp implements pessimistic locking. The class provided by AWS supports it Configure it to FALSE if you dont need it (this will decrease costs and increase performance). Thorough testing would be required to validate your selection. 9