Connecting Your Zend Framework Application to Microsoft Azure


Simply put, cloud computing is a managed, on-demand, scalable computing service which can greatly reduce the time and expense otherwise required to manage corporate IT infrastructure. From the developer's perspective, the implications of delegating expensive and complex issues such as provisioning, visibility, and security to a capable third-party are many, among them the ability to focus the majority of one's time building the most capable, compelling application on the market.

Because no two corporate IT environments are alike, the success of any cloud computing service is going to rest largely on the ability to interoperate within even the most heterogeneous environments. Microsoft's Azure Platform interoperability efforts are indicative of this importance, with great strides being made to provide developers with the ability to connect not only .NET applications to Azure services, but also those built using languages such as Java, PHP, Python, and Ruby. Support for PHP is particularly strong, with the Windows Azure SDK for PHP Developers having been available since November of 2009, in addition to the WindowsAzure4e Eclipse plug-in which greatly reduces the time required to develop and deploy PHP applications supporting Azure.

Azure's PHP support was further strengthened last month with the release of Zend Framework 1.10, which includes native Azure support via the Zend_Service_WindowsAzure component. In this article I'll show you how to connect your Zend Framework application directly to the Windows Azure cloud. In order to follow along with the examples you'll need to create a Windows Azure account.

Creating a Microsoft Azure Account

One of the great advantages to cloud computing is the fact that you only pay for the resources you use. At the same time, the cloud service providers such as Microsoft want to encourage developers to experiment with cloud computing and so it's currently possible to create an Azure account which includes a certain threshold of monthly resource usage at no charge. According to the Azure Website this offer is slated to end on July 31, 2010 so if you're reading this article after the offer expiration date be sure to consult the Website for the latest details.

To create your account head over to the Azure Website and click the Account link. Because you could conceivably surpass the substantial monthly free resource thresholds made available to all Azure users, you will need to provide a credit card during the registration process. Once the registration process is complete you'll be provided with a confirmation e-mail and you can begin using your Azure account.

Configuring Your First Microsoft Azure Project

Once you've received the account confirmation, login to your Windows Azure account via the developer portal. On your home page you will be provided with a list of Azure projects associated with your account, which if you didn't have an Azure account previously will consist of just one default project created during the registration process. Click on the project name, and then click on the New Service. From there you'll be able to choose between adding a Storage Account or Hosted Services to this project (see Figure 1). For the purposes of this tutorial we'll be using the Azure storage services so click the Storage Account link to proceed.

Figure 1. Adding services to your Microsoft Azure project

Next you'll be prompted to assign a name and description with the storage account. I'll call my account NASCAR, as the examples which follow will demonstrate how to use Azure and the Zend Framework to store information about my favorite NASCAR tracks. With the service created you'll next be asked to provide a globally unique public name for the storage account (see Figure 2), which is the URL endopoint which you'll use to manage your hosted data. This public name must consist of at least 3 lowercase alphanumeric characters. You'll also be asked to assign an "affinity group", which merely determines where in the world your data should be stored. For instance, if you live in the United States then you should probably choose Anywhere US as your affinity group region. Once these values have been assigned click the Create button to create your storage account.

Figure 2. Creating a globally unique public name

Once the storage account has been created, you'll be provided with three endpoint URLs, a primary access key, and a secondary access key. Each endpoint URL points is used in conjunction with Azure's three data storage solutions (tables, blobs, and queues). The tables solution allows you to store data using the conceptual notion of a database table, whereas the blog solution allows you to store named files such as images and videos, and the queue solution allows you to manage application messaging. We'll take a look at the tables solution in the forthcoming examples. The primary and secondary access keys are used for authentication purposes, allowing Azure to know that you indeed possess the necessary privileges to manipulate the account data.

Using the Zend_Service_WindowsAzure Component

The Zend_Service_WindowsAzure component is bundled with the Zend Framework version 1.10 and greater, so if you haven't already upgraded please take a moment to do so before proceeding. Once in place, go ahead and create a new project, or consider adding a new controller and corresponding view to experiment with the new Azure features.

Creating a New Storage Table

In order to store information regarding favorite NASCAR tracks in the Azure cloud we'll first need to create a storage table. Keep in mind that although the nomenclature is shared, this is not a relational database table! However you can continue visualizing tables as consisting of columns, rows, and typed-value pairs. To create a table, you'll first connect to the storage service by defining the appropriate endpoint, storage service name, and your primary access key, as demonstrated here:

$storageClient = new Zend_Service_WindowsAzure_Storage_Table(
  '', 'wjgnascar', 'PRIMARY_ACCESS_KEY'

Once connected, create the table using the createTable() method:

$result = $storageClient->createTable('tracks')

Adding Data to the Storage Table

Just as it's possible to rigorously define a relational database table schema in order to enforce what sort of data is inserted into each row, so is it possible to control the type of data inserted into a Windows Azure table. However you don't formally create the table definitions within the storage service; instead you'll do so by creating a client-side schema class in a fashion similar to creating a Zend Framework model, and then populating the schema object before sending the object to the service. Otherwise, you're free to insert just about anything you please into a storage table, even mixing and matching data from one row to the next (although this is of course not recommended). Let's just fly by the seat of our pants and forego using the client-side schema when adding a few tracks to the table:

When inserting data sans a schema class you'll use the Zend_Service_WindowsAzure_Storage_DynamicTableEntity class. The constructor accepts two parameters, including a partition key and row key. The former is used to organize data in groups, whereas the latter is the row's primary key. See the MSDN documentation for more information about the purpose of these values.

With the partition and row keys defined, you can next assign the key value pairs. In the following example we'll create a new row which defines the Atlanta Motor Speedway and its track length:

$row = new Zend_Service_WindowsAzure_Storage_DynamicTableEntity(
  'na', '0001'

$row->name = 'Atlanta Motor Speedway';
$row->length  = 1.540;

$storageClient->insertEntity('tracks', $row);

Querying for Data

You can retrieve data according to its primary key by specifying the partition and row keys, like this:

$entity = $storageClient->retrieveEntityById('tracks', 'na', '000001');
echo "The {$entity->Name} track length is {$entity->Length} miles."

Executing this snippet produces the following output:

The Atlanta Motor Speedway track length is 1.54 miles.

It's also possible to retrieve data using a fluent interface similar to that provided via the Zend_Db component. For instance, use the following syntax to retrieve a list of all tracks stored in the storage table:

$entities = $storageClient->retrieveEntities(
    $storageClient->select()->from('tracks')->where('PartitionKey eq ?', 'na')

foreach ($entities as $entity) {
    echo "{$entity->Name} ($entity->Length miles)<br />";

After adding a few tracks and executing the above code, you'll see results similar to the following:

Atlanta Motor Speedway (1.54 miles)
Auto Club Speedway (2 miles)
Bristol Motor Speedway (0.533 miles)

Works like a charm! Inserting and retrieving data are just a few of the operations you can do using the component. It's also possible to easily update and delete data using native operations. See the component documentation for more information.


Although officially only less than one month old, the Zend Framework's Zend_Service_WindowsAzure component already holds great promise for developers wishing to store application data in the Azure cloud. If you're an early adopter and have already started using these new framework features within your applications, I'd love to hear about what you're doing!

About the Author

Jason Gilmore

Jason Gilmore is a Columbus, Ohio-based developer, consultant, and writer. He's founder of, and author of several popular books "Easy PHP Websites with the Zend Framework", "Easy PayPal with PHP", and "Beginning PHP and MySQL, Third Edition".


  • The Does It Take Cure Erectile Dysfunction Problem?

    Posted by apeeffifielm on 06/21/2013 05:03pm

    Are Safed Musli Capsules Helpful As Part Of Curing Erectile Dysfunction? Those with sickle cell anemia must take caution as well [url= ] pictures of fake viagra [/url] find far more An Effective Medicine for Erectile Dysfunction

  • nfuglo

    Posted by Suttonstu on 03/31/2013 01:46am

    I think oakley sunglasses cheap talk about this and they believe that they should be interested to know the secret of the little Gods space in advance. Well, then ray ban sunglasses should be able to them to establish long-term cooperation and exchanges.ray ban sunglasses sale, At this the young who dressed in black robes temperature Drew voice a bit hoarse, said a closer look now his whole body wrapped in gray matter sank Ruoyouruowu not seem like a gas, it is bit strange and dark, and people could not see his face.ray ban wayfarers, Cluck .ray ban new wayfarer,..... It seems warm Drew was quite smart thing! Hee hee analysis Xiangmoxiangyang, ah, to continue their efforts, sister but always supported you, oh! Sophia clinging to his chest with her white jade-like real estate broker giant pill, with great interest the temperature Drew gasped in admiration. Her attractive obsequiousness temperature Drew Nao Lege flushed, but the role of black robes and fog, other people it is difficult to see his face, but also his own Captain Jack in the eyes can not see The flash point is complex and jealousy.

  • Veswignee saphestanty Atterbarcarty 646433

    Posted by Ril8 on 03/17/2013 08:01pm

    can blow,Balenciaga [url=]Longchamp Tasche[/url] Bags. Zhaoyuan home originally farmers. since 1997 due to [url=]longchamp[/url] repeated practice fraud jailed. Most notably, jailed in June 1997 red carpet months. the exact same year in December as well as practice fraud in jail. After his release, frequently a [url=]longchamp[/url] convergence briefly deception, in 2005 and jailed for 2 along with a [url=]longchamp[/url] half, then in 2008, often towards same charges in any [url=]longchamp[/url] jailed two plus a [url=]Longchamp Tasche[/url] half years. |

  • ghd australia ytobdp

    Posted by Mandyqys on 03/09/2013 09:01am

    longchamp wwwafjtf longchamp sale gefozdrd longchamp bags fyezusma longchamp uk wxtkwein longchamp bags uk aepnbltv

  • ghd australia qwbjew

    Posted by Mandyegi on 03/08/2013 10:45am

    coach outlet fimhyrum coach usa whvovgfh coach factory outlet clmpmtnn coach factory gybhmull

  • ghd australia zzzute

    Posted by Suttonubj on 02/07/2013 04:41pm

    0sMrv christian louboutin iBnz longchamp outlet uMxb michael kors outlet 0mTls 5fYlr chi 0sHny michael kors outlet 3bQmn cheap nfl jerseys 4pUxp nike uk 6wUrh ghd 8hEow ugg 4bQfd toms outlet 4cLkd Tory Burch Black Eddie Sleek Patent Ballet Cheap 9cHps hollister pas cher 7jUgo ghd 0kSod ugg boots

  • ghd australia dpcimq

    Posted by Mandywke on 02/07/2013 09:38am

    4dAnx ugg iRek rIft nike shox sko 9jYei toms outlet 1uJjc cheap hollister 6yMoe ugg 8pXir longchamps 1yBil louis vuitton outlet 1jRvk michael kors outlet 3cChs christian louboutin 9gGgg Anthony Dixon Jersey 3gZya 8mNry 9hZmc ghd 2qDic cheap ugg boots

  • cheap ugg boots kWru eCjg

    Posted by Suttonmsf on 02/07/2013 06:08am

    pMkb louboutin yXmv longchamp sale zUft michael kors outlet 0pHmu 1hEqn chi hair products 9eEqp Michael Kors 7rIym cheap Baltimore Ravens Sideline Legend Authentic Logo Dri-FIT T-Shirt light Blue 8eTnm cheap nike air max 9gGeh ghd 8qYna ugg baratas 1nFvb toms shoes 5vEbv Tory Burch Mini Sling Shoulder Bags brown CheapTory Burch Leather White HandBags CheapTory Burch Messenger Shoulder Khaki Black Bag CheapTory Burch Small Light Grey Handbags CheapTory Burch Wedges 7vSsz hollister pas cher 9mPhl plancha ghd 0yFpp ugg boots sale

  • cheap ugg boots gEfm jFzz

    Posted by Suttontgh on 02/05/2013 04:43am

    uFrz christian louboutin pas cher cMlj longchamp outlet wLyw michael kors sale 0uRap 3xMyu chi straightener 9dOik Michael Kors 4yUne cheap Portland Trail Blazers Fernandez 5# Red Jerseys 5aYpl cheap nike air max 9lCxc ghd 0cLje ugg españa 5pYpz toms coupon code 0tCsn Tory Burch Classic Leather Brown Handbags CheapTory Burch Reva FlatsTory Burch Lady White Handbags CheapTory Burch Zip Front Apricot Handbags CheapNew Tory Burch Lady Grey Handbags Cheap 0bCcz hollister france 2bNlj planchas ghd 0iJur cheap uggs

  • ugg boots bulupe

    Posted by Suttonrez on 01/27/2013 06:48am

    4cFnb nike outlet online vLvl Michael Kors outlet jJmv ugg boots 4nMgk cheap monster beats 4qKhq Cheap nfl jerseys 9gByi uggs australia 7eTqy burberry outlet 3jJyn longchamp bags uk 4pBor cheap nike free run 8aXew cheap uggs 9iSpc beats headphones 6yQvw ugg 8uVvi ghd 1aWoa 3wSsu

  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date