Symfony in the Cloud

25,934 views
24,406 views

Published on

One user's experience as Lead Developer on Nebul.us upgrading a symfony application for deployment to Amazon's cloud-based infrastructure. We will discuss the obstacles met along the way, including juggling master and slave database connections and writing uploaded files to S3. Additionally, integration with the symfony configuration and environments system will be demonstrated, allowing one application to be developed locally and seamlessly deployed to the cloud.

Published in: Technology

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
  3. 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
  5. Wednesday, February 17, 2010
  6. 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
  9. Prototype Wednesday, February 17, 2010
  10. Prototype HTTP PHP Local Filesystem Sessions Uploads MySQL ServerGrove VPS Wednesday, February 17, 2010
  11. What is “The Cloud”? Wednesday, February 17, 2010
  12. I don’t know. 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
  15. Wednesday, February 17, 2010
  16. Production 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
  19. No really, it’s that easy. 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
  22. Database Connections Wednesday, February 17, 2010
  23. Database Connections • Typical database configuration Wednesday, February 17, 2010
  24. Wednesday, February 17, 2010
  25. 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
  28. Wednesday, February 17, 2010
  29. Wednesday, February 17, 2010
  30. Extend the Doctrine ORM • Use the appropriate connection • Doctrine_Query • Doctrine_Record • Doctrine_Collection Wednesday, February 17, 2010
  31. Wednesday, February 17, 2010
  32. Wednesday, February 17, 2010
  33. 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
  35. Wednesday, February 17, 2010
  36. Using the Doctrine DBAL • Doctrine_Manager::connection() • $table->getConnection() Wednesday, February 17, 2010
  37. Wednesday, February 17, 2010
  38. 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
  42. Wednesday, February 17, 2010
  43. Wednesday, February 17, 2010
  44. Connection Listener • Add connection listener to debug mode and test suite Wednesday, February 17, 2010
  45. Wednesday, February 17, 2010
  46. Multiple Connections • Configure multiple connections to the same database Wednesday, February 17, 2010
  47. Wednesday, February 17, 2010
  48. Do you want it? Introducing sfDoctrineMasterSlavePlugin Wednesday, February 17, 2010
  49. File Uploads Wednesday, February 17, 2010
  50. File Uploads • Typical upload form Wednesday, February 17, 2010
  51. Wednesday, February 17, 2010
  52. Wednesday, February 17, 2010
  53. View Layer • Render the uploaded image Wednesday, February 17, 2010
  54. 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
  57. Wednesday, February 17, 2010
  58. Read / write paths • Configure read and write upload paths Wednesday, February 17, 2010
  59. Wednesday, February 17, 2010
  60. Configure Amazon S3 • Toggle integration on/off • Environment buckets Wednesday, February 17, 2010
  61. Wednesday, February 17, 2010
  62. Configure File Uploads • Upload to the write directory • Custom validated file class Wednesday, February 17, 2010
  63. Wednesday, February 17, 2010
  64. 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
  67. Wednesday, February 17, 2010
  68. 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
  70. Wednesday, February 17, 2010
  71. Wednesday, February 17, 2010
  72. Wednesday, February 17, 2010
  73. Session Storage Wednesday, February 17, 2010
  74. Session Storage • Default factories configuration Wednesday, February 17, 2010
  75. Wednesday, February 17, 2010
  76. Wednesday, February 17, 2010
  77. Session Storage • Store session data in the database Wednesday, February 17, 2010
  78. Database Session Storage • Migrate the database Wednesday, February 17, 2010
  79. Wednesday, February 17, 2010
  80. Local Development 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
  82. Deploying 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
  89. Automated Deployment • Rightscale API Wednesday, February 17, 2010
  90. Wednesday, February 17, 2010
  91. Wednesday, February 17, 2010
  92. Questions? Wednesday, February 17, 2010

×