SlideShare a Scribd company logo
Symfony in the Cloud
                                      Kris Wallsmith




                                      February 17, 2010



Wednesday, February 17, 2010
Kris Wallsmith
                 • Freelance web developer,              • JavaScript (moo)
                       consultant, training, audits...
                                                         • @kriswallsmith
                 • 10 years using PHP
                                                         • CTO of Nebul.us
                 • 3 years using symfony
                 • Author of (too) many plugins
                 • 1 year on symfony core team

Wednesday, February 17, 2010
Wednesday, February 17, 2010
What is Nebul.us ?

                 •      Nebul.us is a vibrant and visual life aggregator. In real time you can see
                        what your friends and the public are sharing and discovering online!

                 •      Passively share what you’re doing online

                 •      Show don’t tell




Wednesday, February 17, 2010
Wednesday, February 17, 2010
Wednesday, February 17, 2010
What is Nebul.us really?

                 •      Symfony Framework

                 •      Doctrine ORM

                 •      Zend Framework

                 •      Swift mailer

                 •      and more…


Wednesday, February 17, 2010
What is Nebul.us really?

                 •      Web site

                 •      XML services (Flash and Atom)

                 •      JSON services (browser plugins)

                     •     Up to 12 requests per minute when browsing



Wednesday, February 17, 2010
Prototype



Wednesday, February 17, 2010
Prototype
                                           HTTP

                                            PHP




                                                                    Local Filesystem
                                             Sessions



                                                          Uploads
                               MySQL




                                        ServerGrove VPS

Wednesday, February 17, 2010
What is “The Cloud”?



Wednesday, February 17, 2010
I don’t know.



Wednesday, February 17, 2010
What is “The Cloud”?

                 •      Adds a (big) black box to your stack

                 •      Several virtualized resources

                 •      Scale based on the level of traffic

                 •      Pay only for what you use

                 •      Elastic!

Wednesday, February 17, 2010
It’s cloudy out there

                 •      Amazon

                 •      Rackspace

                 •      Microsoft

                 •      Rightscale



Wednesday, February 17, 2010
Wednesday, February 17, 2010
Production



Wednesday, February 17, 2010
Production
                                            HTTP

                                             PHP




                                                                     Local Filesystem
                                              Sessions



                                                           Uploads
                               MySQL




                                         ServerGrove VPS

Wednesday, February 17, 2010
Production
                                            HTTP

                                             PHP




                                                                     Local Filesystem
                                              Sessions



                                                           Uploads
                               MySQL




                                         ServerGrove VPS

Wednesday, February 17, 2010
No really, it’s that easy.



Wednesday, February 17, 2010
Writing a scalable
                               symfony application
                                     Kris Wallsmith




                                     February 17, 2010



Wednesday, February 17, 2010
Upgrade Points

                 •      Database connections

                 •      File uploads

                 •      Session storage

                 •      Local development

                 •      Deploying


Wednesday, February 17, 2010
Database Connections



Wednesday, February 17, 2010
Database Connections



                 •     Typical database configuration




Wednesday, February 17, 2010
Wednesday, February 17, 2010
Wednesday, February 17, 2010
Database Connections


                 •     One writable “master” connection


                 •     One or more read-only “slave”
                       connections




Wednesday, February 17, 2010
Managing Connections


                 •     Organize read and write connections
                       using a naming convention


                 •     Choose a random read connection




Wednesday, February 17, 2010
Wednesday, February 17, 2010
Wednesday, February 17, 2010
Extend the Doctrine ORM

                 •     Use the appropriate connection

                     • Doctrine_Query
                     • Doctrine_Record
                     • Doctrine_Collection



Wednesday, February 17, 2010
Wednesday, February 17, 2010
Wednesday, February 17, 2010
Wednesday, February 17, 2010
Configure Doctrine


                 •     Set custom query and collection class
                       attributes in manager


                 •     Set custom record class in builder
                       options




Wednesday, February 17, 2010
Wednesday, February 17, 2010
Using the Doctrine DBAL


                 • Doctrine_Manager::connection()
                 • $table->getConnection()




Wednesday, February 17, 2010
Wednesday, February 17, 2010
Wednesday, February 17, 2010
Using the Doctrine DBAL

                 • Doctrine_Manager::getInstance()
                         ->getConnection('master')


                 • $context->getDatabaseManager()
                         ->getDatabase('master')
                         ->getDoctrineConnection()


                 • $configuration
                         ->getWriteConnection()




Wednesday, February 17, 2010
How do we test this?



Wednesday, February 17, 2010
Connection Listener


                 •     Listen to every connection


                 •     Compare type of query to type of
                       connection




Wednesday, February 17, 2010
Wednesday, February 17, 2010
Wednesday, February 17, 2010
Connection Listener


                 •     Add connection listener to debug
                       mode and test suite




Wednesday, February 17, 2010
Wednesday, February 17, 2010
Multiple Connections


                 •     Configure multiple connections to the
                       same database




Wednesday, February 17, 2010
Wednesday, February 17, 2010
Do you want it?
                               Introducing sfDoctrineMasterSlavePlugin




Wednesday, February 17, 2010
File Uploads



Wednesday, February 17, 2010
File Uploads



                 •     Typical upload form




Wednesday, February 17, 2010
Wednesday, February 17, 2010
Wednesday, February 17, 2010
View Layer



                 •     Render the uploaded image




Wednesday, February 17, 2010
Wednesday, February 17, 2010
Amazon S3 Integration


                 •      Must handle file uploads

                 •      Must integrate with the view layer

                 •      Must be disable-able




Wednesday, February 17, 2010
Stream Wrapper


                 •     Zend Amazon S3 stream wrapper

                 • s3://mybucket/image.jpg




Wednesday, February 17, 2010
Wednesday, February 17, 2010
Read / write paths


                 •     Configure read and write upload
                       paths




Wednesday, February 17, 2010
Wednesday, February 17, 2010
Configure Amazon S3


                 •     Toggle integration on/off


                 •     Environment buckets




Wednesday, February 17, 2010
Wednesday, February 17, 2010
Configure File Uploads


                 •     Upload to the write directory


                 •     Custom validated file class




Wednesday, February 17, 2010
Wednesday, February 17, 2010
Wednesday, February 17, 2010
Amazon S3 ACL


                 •     ACL defaults to private


                 •     Extend and change to public-read




Wednesday, February 17, 2010
t, ...
                                  ss ew
                                Ps th
                               M at




Wednesday, February 17, 2010
Wednesday, February 17, 2010
Wednesday, February 17, 2010
View Layer

                 •     Nothing magic


                 •     Custom helper function that uses the
                       configured upload read path


                 •     Search and replace…




Wednesday, February 17, 2010
Wednesday, February 17, 2010
Wednesday, February 17, 2010
Wednesday, February 17, 2010
Session Storage



Wednesday, February 17, 2010
Session Storage



                 •     Default factories configuration




Wednesday, February 17, 2010
Wednesday, February 17, 2010
Wednesday, February 17, 2010
Session Storage



                 •     Store session data in the database




Wednesday, February 17, 2010
Database Session Storage



                 •     Migrate the database




Wednesday, February 17, 2010
Wednesday, February 17, 2010
Local Development



Wednesday, February 17, 2010
Local Development


                 •      One database

                 •      Save uploads to the local filesystem

                 •      Present correct upload path in view layer




Wednesday, February 17, 2010
Deploying



Wednesday, February 17, 2010
Deploying


                 •      Subversion

                     •     svn update

                     •     svn checkout + symlink




Wednesday, February 17, 2010
Deploy with svn update

                 1. Disable

                 2. Update the working copy

                 3. Rebuild model files

                 4. Migrate the database

                 5. Enable


Wednesday, February 17, 2010
Deploy with svn checkout
                 1. Checkout a fresh working copy

                 2. Setup files not in the repository

                 3. Build model files

                 4. Disable current working copy

                 5. Migrate the database

                 6. Update symlink

Wednesday, February 17, 2010
Deploy with svn update

                 1. Disable

                 2. Update the working copy

                 3. Build model files

                 4. Migrate the database

                 5. Enable


Wednesday, February 17, 2010
Deploy with svn checkout
                 1. Checkout a fresh working copy

                 2. Setup files not in the repository

                 3. Build model files

                 4. Disable current working copy

                 5. Migrate the database

                 6. Symlink the new working copy

Wednesday, February 17, 2010
Deployment Strategies

                 •      svn update

                     •     fewer steps

                 •      svn checkout + symlink

                     •     less downtime



Wednesday, February 17, 2010
Automated Deployment



                 •     Rightscale API




Wednesday, February 17, 2010
Wednesday, February 17, 2010
Wednesday, February 17, 2010
Questions?



Wednesday, February 17, 2010

More Related Content

Symfony in the Cloud