News Archive
PhpRiot Newsletter
Your Email Address:

More information

Configuring Zend Framework apps for Windows Azure

Note: This article was originally published at Planet PHP on 19 December 2011.
Planet PHP

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.

As you can see, your system now falls appart into all differentcomponents that are systems by themselves. And each system has itsown purpose, completely independent from each other.

With Zend Frameworkdeveloping applications running on these separate compontentsbecomes really easy. It's like having your cloud toolbox right inyour pocket.


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.adapter = "pdo_mysql" = ""
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.adapter = "pdo_mysql" = ""
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.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.adapter = "SQLSRV" = ""
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!


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.use_only_cookies = true
resources.session.gc_maxlifetime = 864000
resources.session.remember_me_seconds = 864000
resources.session.saveHandler.class = "Zend_Session_SaveHandler_DbTable" = "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.


Just like databases, providing caching for your applicationrequires just a few simple configuration settings, this examplesets up a memcache service. = Core
resources.cachemanager.memcached.frontend.options.automatic_serialization = On = Libmemcached = localhost = 11211 = On

Caching on the cloud requires a little differen

Truncated by Planet PHP, read more at the original (another 4574 bytes)