Symfony in the Cloud
- 1. Symfony in the Cloud
Kris Wallsmith
February 17, 2010
Wednesday, February 17, 2010
- 2. 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
- 4. 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
- 7. What is Nebul.us really?
• Symfony Framework
• Doctrine ORM
• Zend Framework
• Swift mailer
• and more…
Wednesday, February 17, 2010
- 8. 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
- 10. Prototype
HTTP
PHP
Local Filesystem
Sessions
Uploads
MySQL
ServerGrove VPS
Wednesday, February 17, 2010
- 13. 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
- 14. It’s cloudy out there
• Amazon
• Rackspace
• Microsoft
• Rightscale
Wednesday, February 17, 2010
- 17. Production
HTTP
PHP
Local Filesystem
Sessions
Uploads
MySQL
ServerGrove VPS
Wednesday, February 17, 2010
- 18. Production
HTTP
PHP
Local Filesystem
Sessions
Uploads
MySQL
ServerGrove VPS
Wednesday, February 17, 2010
- 20. Writing a scalable
symfony application
Kris Wallsmith
February 17, 2010
Wednesday, February 17, 2010
- 21. Upgrade Points
• Database connections
• File uploads
• Session storage
• Local development
• Deploying
Wednesday, February 17, 2010
- 26. Database Connections
• One writable “master” connection
• One or more read-only “slave”
connections
Wednesday, February 17, 2010
- 27. Managing Connections
• Organize read and write connections
using a naming convention
• Choose a random read connection
Wednesday, February 17, 2010
- 30. Extend the Doctrine ORM
• Use the appropriate connection
• Doctrine_Query
• Doctrine_Record
• Doctrine_Collection
Wednesday, February 17, 2010
- 34. Configure Doctrine
• Set custom query and collection class
attributes in manager
• Set custom record class in builder
options
Wednesday, February 17, 2010
- 36. Using the Doctrine DBAL
• Doctrine_Manager::connection()
• $table->getConnection()
Wednesday, February 17, 2010
- 39. Using the Doctrine DBAL
• Doctrine_Manager::getInstance()
->getConnection('master')
• $context->getDatabaseManager()
->getDatabase('master')
->getDoctrineConnection()
• $configuration
->getWriteConnection()
Wednesday, February 17, 2010
- 40. How do we test this?
Wednesday, February 17, 2010
- 41. Connection Listener
• Listen to every connection
• Compare type of query to type of
connection
Wednesday, February 17, 2010
- 44. Connection Listener
• Add connection listener to debug
mode and test suite
Wednesday, February 17, 2010
- 46. Multiple Connections
• Configure multiple connections to the
same database
Wednesday, February 17, 2010
- 48. Do you want it?
Introducing sfDoctrineMasterSlavePlugin
Wednesday, February 17, 2010
- 50. File Uploads
• Typical upload form
Wednesday, February 17, 2010
- 53. View Layer
• Render the uploaded image
Wednesday, February 17, 2010
- 55. Amazon S3 Integration
• Must handle file uploads
• Must integrate with the view layer
• Must be disable-able
Wednesday, February 17, 2010
- 56. Stream Wrapper
• Zend Amazon S3 stream wrapper
• s3://mybucket/image.jpg
Wednesday, February 17, 2010
- 58. Read / write paths
• Configure read and write upload
paths
Wednesday, February 17, 2010
- 60. Configure Amazon S3
• Toggle integration on/off
• Environment buckets
Wednesday, February 17, 2010
- 62. Configure File Uploads
• Upload to the write directory
• Custom validated file class
Wednesday, February 17, 2010
- 65. Amazon S3 ACL
• ACL defaults to private
• Extend and change to public-read
Wednesday, February 17, 2010
- 66. t, ...
ss ew
Ps th
M at
Wednesday, February 17, 2010
- 69. View Layer
• Nothing magic
• Custom helper function that uses the
configured upload read path
• Search and replace…
Wednesday, February 17, 2010
- 74. Session Storage
• Default factories configuration
Wednesday, February 17, 2010
- 77. Session Storage
• Store session data in the database
Wednesday, February 17, 2010
- 81. Local Development
• One database
• Save uploads to the local filesystem
• Present correct upload path in view layer
Wednesday, February 17, 2010
- 83. Deploying
• Subversion
• svn update
• svn checkout + symlink
Wednesday, February 17, 2010
- 84. 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
- 85. 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
- 86. 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
- 87. 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
- 88. Deployment Strategies
• svn update
• fewer steps
• svn checkout + symlink
• less downtime
Wednesday, February 17, 2010