Download - Symfony in the Cloud
![Page 1: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/1.jpg)
Symfony in the CloudKris Wallsmith
February 17, 2010
Wednesday, February 17, 2010
![Page 2: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/2.jpg)
Kris Wallsmith
• Freelance web developer, consultant, training, audits...
• 10 years using PHP
• 3 years using symfony
• Author of (too) many plugins
• 1 year on symfony core team
• JavaScript (moo)
• @kriswallsmith
• CTO of Nebul.us
Wednesday, February 17, 2010
![Page 3: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/3.jpg)
Wednesday, February 17, 2010
![Page 4: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/4.jpg)
What is Nebul.us ?
• Nebul.us is a vibrant and visual life aggregator. In real time you can seewhat 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
![Page 5: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/5.jpg)
Wednesday, February 17, 2010
![Page 6: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/6.jpg)
Wednesday, February 17, 2010
![Page 7: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/7.jpg)
• Symfony Framework
• Doctrine ORM
• Zend Framework
• Swift mailer
• and more…
What is Nebul.us really?
Wednesday, February 17, 2010
![Page 8: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/8.jpg)
• Web site
• XML services (Flash and Atom)
• JSON services (browser plugins)
• Up to 12 requests per minute when browsing
What is Nebul.us really?
Wednesday, February 17, 2010
![Page 9: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/9.jpg)
Prototype
Wednesday, February 17, 2010
![Page 10: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/10.jpg)
HTTP
PHP
MySQ
L
Uploads
ServerGrove VPSSessions
Local Filesystem
Prototype
Wednesday, February 17, 2010
![Page 11: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/11.jpg)
What is “The Cloud”?
Wednesday, February 17, 2010
![Page 12: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/12.jpg)
I don’t know.
Wednesday, February 17, 2010
![Page 13: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/13.jpg)
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
![Page 14: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/14.jpg)
It’s cloudy out there
• Amazon
• Rackspace
• Microsoft
• Rightscale
Wednesday, February 17, 2010
![Page 15: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/15.jpg)
Wednesday, February 17, 2010
![Page 16: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/16.jpg)
Production
Wednesday, February 17, 2010
![Page 17: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/17.jpg)
Production
HTTP
PHP
MySQ
L
Uploads
ServerGrove VPSSessions
Local Filesystem
Wednesday, February 17, 2010
![Page 18: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/18.jpg)
Production
HTTP
PHP
MySQ
L
Uploads
ServerGrove VPSSessions
Local Filesystem
Wednesday, February 17, 2010
![Page 19: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/19.jpg)
No really, it’s that easy.
Wednesday, February 17, 2010
![Page 20: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/20.jpg)
Writing a scalablesymfony application
Kris Wallsmith
February 17, 2010
Wednesday, February 17, 2010
![Page 21: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/21.jpg)
Upgrade Points
• Database connections
• File uploads
• Session storage
• Local development
• Deploying
Wednesday, February 17, 2010
![Page 22: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/22.jpg)
Database Connections
Wednesday, February 17, 2010
![Page 23: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/23.jpg)
Database Connections
• Typical database configuration
Wednesday, February 17, 2010
![Page 24: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/24.jpg)
Wednesday, February 17, 2010
![Page 25: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/25.jpg)
Wednesday, February 17, 2010
![Page 26: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/26.jpg)
Database Connections
• One writable “master” connection
• One or more read-only “slave” connections
Wednesday, February 17, 2010
![Page 27: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/27.jpg)
Managing Connections
• Organize read and write connections using a naming convention
• Choose a random read connection
Wednesday, February 17, 2010
![Page 28: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/28.jpg)
Wednesday, February 17, 2010
![Page 29: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/29.jpg)
Wednesday, February 17, 2010
![Page 30: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/30.jpg)
Extend the Doctrine ORM
• Use the appropriate connection
• Doctrine_Query
• Doctrine_Record
• Doctrine_Collection
Wednesday, February 17, 2010
![Page 31: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/31.jpg)
Wednesday, February 17, 2010
![Page 32: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/32.jpg)
Wednesday, February 17, 2010
![Page 33: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/33.jpg)
Wednesday, February 17, 2010
![Page 34: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/34.jpg)
Configure Doctrine
• Set custom query and collection class attributes in manager
• Set custom record class in builder options
Wednesday, February 17, 2010
![Page 35: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/35.jpg)
Wednesday, February 17, 2010
![Page 36: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/36.jpg)
Using the Doctrine DBAL
• Doctrine_Manager::connection()
• $table->getConnection()
Wednesday, February 17, 2010
![Page 37: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/37.jpg)
Wednesday, February 17, 2010
![Page 38: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/38.jpg)
Wednesday, February 17, 2010
![Page 39: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/39.jpg)
Using the Doctrine DBAL
• Doctrine_Manager::getInstance() ->getConnection('master')
• $context->getDatabaseManager() ->getDatabase('master') ->getDoctrineConnection()
• $configuration ->getWriteConnection()
Wednesday, February 17, 2010
![Page 40: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/40.jpg)
How do we test this?
Wednesday, February 17, 2010
![Page 41: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/41.jpg)
Connection Listener
• Listen to every connection
• Compare type of query to type of connection
Wednesday, February 17, 2010
![Page 42: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/42.jpg)
Wednesday, February 17, 2010
![Page 43: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/43.jpg)
Wednesday, February 17, 2010
![Page 44: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/44.jpg)
Connection Listener
• Add connection listener to debugmode and test suite
Wednesday, February 17, 2010
![Page 45: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/45.jpg)
Wednesday, February 17, 2010
![Page 46: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/46.jpg)
Multiple Connections
• Configure multiple connections to the same database
Wednesday, February 17, 2010
![Page 47: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/47.jpg)
Wednesday, February 17, 2010
![Page 48: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/48.jpg)
Do you want it?Introducing sfDoctrineMasterSlavePlugin
Wednesday, February 17, 2010
![Page 49: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/49.jpg)
File Uploads
Wednesday, February 17, 2010
![Page 50: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/50.jpg)
File Uploads
• Typical upload form
Wednesday, February 17, 2010
![Page 51: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/51.jpg)
Wednesday, February 17, 2010
![Page 52: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/52.jpg)
Wednesday, February 17, 2010
![Page 53: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/53.jpg)
View Layer
• Render the uploaded image
Wednesday, February 17, 2010
![Page 54: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/54.jpg)
Wednesday, February 17, 2010
![Page 55: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/55.jpg)
Amazon S3 Integration
• Must handle file uploads
• Must integrate with the view layer
• Must be disable-able
Wednesday, February 17, 2010
![Page 56: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/56.jpg)
Stream Wrapper
• Zend Amazon S3 stream wrapper
• s3://mybucket/image.jpg
Wednesday, February 17, 2010
![Page 57: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/57.jpg)
Wednesday, February 17, 2010
![Page 58: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/58.jpg)
Read / write paths
• Configure read and write upload paths
Wednesday, February 17, 2010
![Page 59: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/59.jpg)
Wednesday, February 17, 2010
![Page 60: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/60.jpg)
Configure Amazon S3
• Toggle integration on/off
• Environment buckets
Wednesday, February 17, 2010
![Page 61: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/61.jpg)
Wednesday, February 17, 2010
![Page 62: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/62.jpg)
Configure File Uploads
• Upload to the write directory
• Custom validated file class
Wednesday, February 17, 2010
![Page 63: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/63.jpg)
Wednesday, February 17, 2010
![Page 64: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/64.jpg)
Wednesday, February 17, 2010
![Page 65: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/65.jpg)
Amazon S3 ACL
• ACL defaults to private
• Extend and change to public-read
Wednesday, February 17, 2010
![Page 66: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/66.jpg)
Pssst,
Matthew
...
Wednesday, February 17, 2010
![Page 67: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/67.jpg)
Wednesday, February 17, 2010
![Page 68: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/68.jpg)
Wednesday, February 17, 2010
![Page 69: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/69.jpg)
View Layer
• Nothing magic
• Custom helper function that uses the configured upload read path
• Search and replace…
Wednesday, February 17, 2010
![Page 70: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/70.jpg)
Wednesday, February 17, 2010
![Page 71: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/71.jpg)
Wednesday, February 17, 2010
![Page 72: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/72.jpg)
Wednesday, February 17, 2010
![Page 73: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/73.jpg)
Session Storage
Wednesday, February 17, 2010
![Page 74: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/74.jpg)
Session Storage
• Default factories configuration
Wednesday, February 17, 2010
![Page 75: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/75.jpg)
Wednesday, February 17, 2010
![Page 76: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/76.jpg)
Wednesday, February 17, 2010
![Page 77: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/77.jpg)
Session Storage
• Store session data in the database
Wednesday, February 17, 2010
![Page 78: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/78.jpg)
Database Session Storage
• Migrate the database
Wednesday, February 17, 2010
![Page 79: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/79.jpg)
Wednesday, February 17, 2010
![Page 80: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/80.jpg)
Local Development
Wednesday, February 17, 2010
![Page 81: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/81.jpg)
Local Development
• One database
• Save uploads to the local filesystem
• Present correct upload path in view layer
Wednesday, February 17, 2010
![Page 82: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/82.jpg)
Deploying
Wednesday, February 17, 2010
![Page 83: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/83.jpg)
Deploying
• Subversion
• svn update
• svn checkout + symlink
Wednesday, February 17, 2010
![Page 84: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/84.jpg)
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
![Page 85: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/85.jpg)
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
![Page 86: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/86.jpg)
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
![Page 87: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/87.jpg)
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
![Page 88: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/88.jpg)
Deployment Strategies
• svn update
• fewer steps
• svn checkout + symlink
• less downtime
Wednesday, February 17, 2010
![Page 89: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/89.jpg)
Automated Deployment
• Rightscale API
Wednesday, February 17, 2010
![Page 90: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/90.jpg)
Wednesday, February 17, 2010
![Page 91: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/91.jpg)
Wednesday, February 17, 2010
![Page 92: Symfony in the Cloud](https://reader034.vdocument.in/reader034/viewer/2022052522/54b750174a795967588b4633/html5/thumbnails/92.jpg)
Questions?
Wednesday, February 17, 2010