SlideShare a Scribd company logo
DynamoDB for PHP Session Storage

            25 April 2012




                                     Andreas Chatzakis
                                   @achatzakis on twitter
                                            AWSUG Greece
                      Not affiliated with, sponsored or endorsed by AWS
Sessions in the cloud


Sticky sessions?
Memcache?
MySQL?
Redis?
Enter DynamoDB:
Highly available – Consistently performing
Persistent
AWS SDK now includes drop in PHP session
handler replacement

                                               2
Create a user




            3
Create a table




             4
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
Install & Configure SDK

Install the latest version of the SDK on your web server
image - 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
Instantiate

require_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
Update php.ini



session.save_handler = user
auto_prepend_file = /path-to/dynamosessions.php



 Restart web server
 Test
 Snapshot fresh AMI




                                                    8
Considerations


Estimate read/write throughput requirements
 Validate post go live
Does your application need locking? By default
php 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

More Related Content

PPTX
Mga pang ugnay
PPTX
Filipino 9 - Tunggalian (Mga Halimbawa ng Tunggalian).pptx
PPT
For Education - Ibong Adarna
DOCX
"Sigaw" - Gay C. Tello
PPTX
tanka at haiku matatalinhaga.pptx
PPTX
YUNIT IV PAHAYAGAN SA PILIPINAS.pptx
PPTX
Filipino-9-Quarter 1- TULANG ASYANO.pptx
PPTX
Ang kababaihan ng taiwan (1)
Mga pang ugnay
Filipino 9 - Tunggalian (Mga Halimbawa ng Tunggalian).pptx
For Education - Ibong Adarna
"Sigaw" - Gay C. Tello
tanka at haiku matatalinhaga.pptx
YUNIT IV PAHAYAGAN SA PILIPINAS.pptx
Filipino-9-Quarter 1- TULANG ASYANO.pptx
Ang kababaihan ng taiwan (1)

What's hot (20)

PPTX
Mga Karaniwang Uri ng Anggulo at Kuha ng Kamera
PPT
Pag sang ayon at pasalungat
PPTX
Aralin 1_ Kontemporaryong Panitikan - Pahayagan pptx.pptx
PDF
Grade 8 Learning Module in Filipino - Complete
PPTX
Pagsasaling - wika
PDF
232413121 walang-sugat-ni-severino-reyes
PPTX
G8-Florante at Laura (Kabanata 5).pptx
PPTX
Pag-aalay kay Selya.pptx
PPTX
LP 1 ppt..pptx
PPTX
1 wika ng pagsasalin
PPT
El Fili Kabanata 5 noche buena ng isang kutsero
PPTX
YOU-AND-YOUR-PATROL-SLIDE.pptx
PPTX
Ang buwang hugis suklay
PPTX
Kay estella zeehandelaar
PPTX
Fil9 (1)
PDF
Nasa Huli ang Pagsisisi
DOCX
Pre test panahon ng kastila
PPTX
Estruktura ng Wikang Filipino (aralin 1).pptx
PPTX
203-Mga-Bantas na ginagamit sa mga sulating filipino pormal at di pormal.pptx
PDF
KABANATA 1-3 (PEREZ) Noli Me Tangere .pdf
Mga Karaniwang Uri ng Anggulo at Kuha ng Kamera
Pag sang ayon at pasalungat
Aralin 1_ Kontemporaryong Panitikan - Pahayagan pptx.pptx
Grade 8 Learning Module in Filipino - Complete
Pagsasaling - wika
232413121 walang-sugat-ni-severino-reyes
G8-Florante at Laura (Kabanata 5).pptx
Pag-aalay kay Selya.pptx
LP 1 ppt..pptx
1 wika ng pagsasalin
El Fili Kabanata 5 noche buena ng isang kutsero
YOU-AND-YOUR-PATROL-SLIDE.pptx
Ang buwang hugis suklay
Kay estella zeehandelaar
Fil9 (1)
Nasa Huli ang Pagsisisi
Pre test panahon ng kastila
Estruktura ng Wikang Filipino (aralin 1).pptx
203-Mga-Bantas na ginagamit sa mga sulating filipino pormal at di pormal.pptx
KABANATA 1-3 (PEREZ) Noli Me Tangere .pdf
Ad

Similar to DynamoDB for PHP sessions (20)

PDF
Amazon Web Services for PHP Developers
PPT
Everyone loves PHP
PDF
Bottom to Top Stack Optimization with LAMP
PDF
Bottom to Top Stack Optimization - CICON2011
PDF
Hybrid Cloud PHPUK2012
PDF
Develop and deploy using Hybrid Cloud Strategies confoo2012
PPTX
Moving to the Cloud: AWS, Zend, RightScale
PDF
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
PDF
Top ten-list
PDF
Solving the C20K Problem: PHP Performance and Scalability
PDF
Solving the C20K Problem: PHP Performance and Scalability
PDF
Hopping in clouds - phpuk 17
PDF
Caching with Memcached and APC
PDF
Dutch php conference_apc_mem2010
PDF
Gear6 and Scaling Website Performance: Caching Session and Profile Data with...
PDF
Jeff Rigby on Scaling Drupal in the Enterprise
PDF
Facebook的缓存系统
PDF
Performance scalability brandonlyon
KEY
Profiling php applications
PPT
Heavy Web Optimization: Backend
Amazon Web Services for PHP Developers
Everyone loves PHP
Bottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization - CICON2011
Hybrid Cloud PHPUK2012
Develop and deploy using Hybrid Cloud Strategies confoo2012
Moving to the Cloud: AWS, Zend, RightScale
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
Top ten-list
Solving the C20K Problem: PHP Performance and Scalability
Solving the C20K Problem: PHP Performance and Scalability
Hopping in clouds - phpuk 17
Caching with Memcached and APC
Dutch php conference_apc_mem2010
Gear6 and Scaling Website Performance: Caching Session and Profile Data with...
Jeff Rigby on Scaling Drupal in the Enterprise
Facebook的缓存系统
Performance scalability brandonlyon
Profiling php applications
Heavy Web Optimization: Backend
Ad

More from Andreas Chatzakis (6)

PDF
ElasticSearch on AWS - Real Estate portal case study (Spitogatos.gr)
PDF
Newvem Community - Cloud Management
PDF
Scalr Demo
PDF
Cloud Management
PDF
An intro to Amazon Web Services (AWS)
PDF
AWS case study: real estate portal
ElasticSearch on AWS - Real Estate portal case study (Spitogatos.gr)
Newvem Community - Cloud Management
Scalr Demo
Cloud Management
An intro to Amazon Web Services (AWS)
AWS case study: real estate portal

Recently uploaded (20)

PDF
Empathic Computing: Creating Shared Understanding
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
A Presentation on Artificial Intelligence
PPT
Teaching material agriculture food technology
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Approach and Philosophy of On baking technology
PPTX
MYSQL Presentation for SQL database connectivity
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Machine learning based COVID-19 study performance prediction
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Spectroscopy.pptx food analysis technology
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
NewMind AI Weekly Chronicles - August'25-Week II
Empathic Computing: Creating Shared Understanding
Digital-Transformation-Roadmap-for-Companies.pptx
A Presentation on Artificial Intelligence
Teaching material agriculture food technology
Spectral efficient network and resource selection model in 5G networks
Encapsulation_ Review paper, used for researhc scholars
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Approach and Philosophy of On baking technology
MYSQL Presentation for SQL database connectivity
The Rise and Fall of 3GPP – Time for a Sabbatical?
Machine learning based COVID-19 study performance prediction
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
MIND Revenue Release Quarter 2 2025 Press Release
Spectroscopy.pptx food analysis technology
sap open course for s4hana steps from ECC to s4
Building Integrated photovoltaic BIPV_UPV.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Network Security Unit 5.pdf for BCA BBA.
NewMind AI Weekly Chronicles - August'25-Week II

DynamoDB for PHP sessions

  • 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 cloud Sticky sessions? Memcache? MySQL? Redis? Enter DynamoDB: Highly available – Consistently performing Persistent AWS SDK now includes drop in PHP session handler replacement 2
  • 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 SDK Install the latest version of the SDK on your web server image - 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. Instantiate require_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.ini session.save_handler = user auto_prepend_file = /path-to/dynamosessions.php Restart web server Test Snapshot fresh AMI 8
  • 9. Considerations Estimate read/write throughput requirements Validate post go live Does your application need locking? By default php 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