Share via


Support for Worker Roles in the Windows Azure SDK for PHP

June 7, 2012 update: The Microsoft Windows Azure team has released a new Windows Azure SDK for PHP. This release is part of an effort to keep PHP client libraries up to date with new Windows Azure features and to make PHP a first-class citizen in Windows Azure. The latest client libraries are on GitHub: https://github.com/WindowsAzure/azure-sdk-for-php. While the SDK hosted on CodePlex will continue to work for the foreseeable future, it is strongly recommended that new PHP/Windows Azure application use the SDK hosted on GitHub.

The work done by Maarten Balliauw and other contributors in building the SDK hosted on CodePlex was critical in unifying the PHP developer experience for Windows Azure. The Windows Azure team is grateful to these contributors for their pioneering work and looks forward to their continued support (and yours!) in adding to the new SDK on GitHub.

Thanks,

      
The Windows Azure Team


Since the release of version 4.0 of the Windows Azure SDK for PHP, one of the missing pieces has been the ability to package Worker roles as part of a deployment. As of this past weekend, that is no longer the case. Maarten Balliauw, the main contributor to the SDK, has added support for worker roles to the default scaffolder, which now makes it extremely easy to run not only one worker role, but many worker roles (and many web roles too). In this post, I’ll show you how to package and deploy a worker role as part of a web application.

Note: If you aren’t familiar with scaffolds, I’d suggest reading the following tutorials for context:

Here are the steps to including a Worker role in an Azure/PHP deployment:

1. Get the latest Windows Azure SDK for PHP.

As of this writing, you’ll need to get the latest bits from here: https://phpazure.codeplex.com/SourceControl/list/changesets. You should soon see these latest bits available for download directly from the CodePlex site here: https://phpazure.codeplex.com/releases/view/73437. If you haven’t already installed and set up the SDK, you can do so by following this tutorial: Set Up the Windows Azure SDK for PHP.

2. Run the default scaffolder.

This tutorial, Build and Deploy a Windows Azure PHP Application, will give you a good idea of what a scaffold is and how to use the default scaffold in the SDK. The short story is that a scaffold provides a project skeleton that takes care of much of the set up and configuration you would have to do for a Windows Azure PHP project. All you have to do is add your source code. To create the default scaffold with a worker role, run this command:

 scaffolder run -out="c:\path\to\output\directory" -web="WebRoleName" -workers="WorkerRoleName"

I ran this command with my output directory set to c:\workspace\test, a Web role with name WebRole1, and a Worker role with name WorkerRole1. Here is what you should see as the resulting directory:

image

Note: With the new SDK, you can create a scaffold that has many Web roles and many Worker roles with a command similar to this:

 scaffolder run -out="c:\path\to\output\directory" -web="WebRoleName1,WebRoleName2,...,WebRoleNameN" -workers="WorkerRoleName1,WorkerRoleName2,...,WorkerRoleNameN""
3. Add the source code for your Web and Worker roles.

Now, simply add the source code for your Web Role to the WebRole1 directory and the source code for your Worker role to the WorkerRole1 directory.

4. Test by running in the Compute Emulator.

You can test your code by running your project in the Windows Azure Compute Emulator with this command:

 package create -in="C:\path\to\scaffold\directory" -out="c:\path\to\drop\packge\files" -dev=true

So in my case, I set the –in parameter to c:\workspace\test and the –out parameter to c:\workspace\test\build.

5. Package and deploy to Windows Azure.

Finally, when you are ready to deploy your application to Windows Azure, you can do so with this command (same as above but with dev=false):

 package create -in="C:\path\to\scaffold\directory" -out="c:\path\to\drop\packge\files" -dev=false

In your output directory, you should find two files: a .cspkg file and a .cscfg file. You can deploy these to Windows Azure through the developer portal: https://windows.azure.com/ (more info on how to do this here). Other deployment options include using the command line tools available in the SDK, or  using WAZ-PHP-Utils tools available on GitHub (and developed by Ben Lobaugh).

That’s it. Of course, all of this begs the question, WHY use worker roles? The answer to that (or at least one answer) is coming in my next post.

Thanks.

-Brian

Share this on Twitter