Configuring Zend Framework apps for Windows Azure
Building web applications is nothing new anymore, as we've beendoing it since the early days of the internet, but we've alwaysdone this on a single system. Even when Zend Framework came round,we kept doing the same thing and build apps for a singleenvironment.
But as I've discussed already in my previous article, developing for the cloud requires anotherapproach.
With Zend Frameworkdeveloping applications running on these separate compontentsbecomes really easy. It's like having your cloud toolbox right inyour pocket.
Databases
With Zend Framework,connecting to databases is really easy and swapping out a databasebrand is just a matter of modifying your configurationapplication/configs/application.ini.
resources.db.params.host = "10.20.30.40"
resources.db.params.username = "user1"
resources.db.params.password = "secret"
resources.db.params.dbname = "db1"
resources.db.isDefaultTableAdapter = true
Even if you need to connect to multiple databases, you can justpile them up as configuration setting and be done with it.
resources.multidb.server1.host = "10.20.30.40"
resources.multidb.server1.username = "user1"
resources.multidb.server1.password = "secret1"
resources.multidb.server1.dbname = "db1"
resources.multidb.server1.default = true
resources.multidb.server2.adapter = "pdo_pgsql"
resources.multidb.server2.host = "10.20.30.41"
resources.multidb.server2.username = "user2"
resources.multidb.server2.password = "secret2"
resources.multidb.server2.dbname = "db2"
resources.multidb.server3.adapter = "pdo_sqlite"
resources.multidb.server3.dbname = APPLICATION_PATH "/files/db/project.db"
But this is just the basics. When dealing with the cloud youoften get a connection string for the host, so it's real easy tohook up to an relational database in the cloud. Here's an exampleto connecting to SQL Azure.
resources.db.params.host = "abcdefghijk.database.windows.net"
resources.db.params.port = 1234
resources.db.params.username = "user1"
resources.db.params.password = "secret"
resources.db.params.dbname = "db1"
resources.db.isDefaultTableAdapter = true
Bottom line, no worries connecting to a cloud database. Zend Framework has yourback!
Sessions
As you want to assist your visitors as much as possible, youprobably want to use sessions in your application. If you don'tconfigure anything, PHP stores session on your filesystem bydefault and so does ZendFramework.
For the cloud, you don't want to write to your local filesystem,so you set up session storage. I chose to use the SQL Azure serverI already had setup using the following settings.
resources.session.gc_maxlifetime = 864000
resources.session.remember_me_seconds = 864000
resources.session.saveHandler.class = "Zend_Session_SaveHandler_DbTable"
resources.session.saveHandler.options.name = "session"
resources.session.saveHandler.options.primary = "id"
resources.session.saveHandler.options.modifiedColumn = "modified"
resources.session.saveHandler.options.dataColumn = "data"
resources.session.saveHandler.options.lifetimeColumn = "lifetime"
No further changes need to be done as all fields are defined andthis Zend_Session_SaveHandler_DbTable takes care of all the rest.
Caching
Just like databases, providing caching for your applicationrequires just a few simple configuration settings, this examplesets up a memcache service.
resources.cachemanager.memcached.frontend.options.automatic_serialization = On
resources.cachemanager.memcached.backend.name = Libmemcached
resources.cachemanager.memcached.backend.options.servers.one.host = localhost
resources.cachemanager.memcached.backend.options.servers.one.port = 11211
resources.cachemanager.memcached.backend.options.servers.one.persistent = On
Caching on the cloud requires a little differen
Truncated by Planet PHP, read more at the original (another 4574 bytes)


