Archive for February, 2011

Planning my Azure application (Part 1)

[This is a blog post related to the PHP on Azure competition.]

I’ve had some time to think about how I’m going to build the application, and I’ve got some ideas for how I’d like to proceed. At this point I’d have liked to set my development environment up with the Azure tools and had a play with the example applications I’ve come across, mostly to get a feel for what’s possible, but unfortunately upon trying to install the Azure SDK I discovered that it requires Windows Vista or 7, and at home I’m still running XP. I toyed with the idea of installing Windows 7 into a Virtual Machine, which would probably be the quickest route to get back on track, but since I have been intending to migrate to 7 for a while this is probably the right time; technology is obviously evolving beyond XP (finally!).

So in the interim while I work on an upgrade I’ll start planning my CMS application. I’ve been thinking about the type of libraries and frameworks I want to take advantage of, and how I’m going to knit them together. I won’t be able to check they work on Windows Azure ’til I get access to a machine, but I’m fairly confident that the vast majority, if not all of them, will work on the platform.

Firstly I’ll be using Zend Framework to provide the backbone of the application. I’ve not yet decided how much of the framework I’ll be taking advantage of, but I’ll definitely be using Zend_Application and its related classes to handle the bootstrapping phase of the application, because its flexibility will be key when loading the other libraries I intend to use. The application will then utilise the ubiquitous MVC pattern, using the following components:

As I mentioned in my last post I don’t yet know how I’m going to work with the data layer: I really want to use Doctrine 2, which I know has SQL Server (and thus, I’m assuming, SQL Azure) support, but I’m not aware of similar support for Table Storage. Brian Swan posted a tutorial where he uses the OAuth SDK to access Table Storage, and that follows a similar annotations-driven approach to Doctrine 2; if one doesn’t exist, I’m wondering how much work it would take to write a Table Storage driver for Doctrine.

Functionally, it may be possible to use Table Storage exclusively within the app (it sounds like it’ll be cheaper) but there appear to be some crucial missing features, like full-text searching. I’ve been spoiled working with Solr for the past few years; I’d like to use Solr here, but have read conflicting reports as to whether it’s possible. The way things are looking, I’ll try to use Table Storage in the first instance, then fall back to SQL Azure if it doesn’t give me what I need.

For the view / templating component I’ll probably take the path of least resistance, which will probably mean Zend_View. My main requirement is easy support for different RESTful response response formats, i.e. HTML, XML and JSON, especially since I intend for the backend of the app to be JavaScript-heavy (using ExtJS 4) which will mean a lot of JSON.

Zend’s Controller classes are great, and I’ll probably use their routing system as well since it has RESTful support. There’s not much more to say about that really!

So in an ideal world, this is how the application will be laid out:

An overview of the application architecture

Next I’ll think in more detail about the frontend and backend applications. Now I have to go to PC World to buy a hard drive and a copy of Windows 7…

Learning about Windows Azure

[This is a blog post related to the PHP on Azure competition.]

I’ve spent the last few days reading about Windows Azure, mostly just trying to get a feel for what features it has and how I could use them in an application. The competition rules suggest that entrants “can earn extra points by using other parts of the Windows Azure platform” and the more I get to learn, the better, so I’m going to try to make use of as much of Azure’s functionality as possible.

Though I haven’t yet decided what application I’ll be writing it’ll probably be some sort of a CMS – it’s the genre of web app I’m most familiar and its likely I’ll get more done in the short time frame I have if I stick to what I know best. As a result I’ve been looking at Azure’s feature list and thinking “how I can map this platform feature to a feature of a CMS?”

I found plenty of resources which helped me get an overview of Azure, and which I’m sure I’ll continue to use as I progress. The most helpful were:

The Sitepoint article does a great job of summarising what Azure offers a PHP developer. As I was reading it I kept thinking “Ooh, that’d come in handy for this” or “That’d make so-and-so easy…” – here’s my reaction to some of the topics covered in the article.

Platform as a Service

The article starts by explaining that unlike, for example, Amazon’s EC2, which is an example of Infrastucture-as-a-Service, Windows Azure is a Platform-as-a-service. This essentially means that a developer using Azure doesn’t need to worry about maintaining the server, and just has to focus on deploying and configuring the applications that run on it. This sounds good to me; while my experiences of EC2 have been mostly good, there is a lot of work involved with getting servers into a state where they are usable. This can be mitigated somewhat by creating build scripts, but even then these have to be maintained, while managing server security is another headache that I’d be glad to be rid of. I’m optimistic that Azure will prove itself to be very hospitable, though I suppose there’s a chance that it’ll be too inflexible for more demanding applications that require atypical server configurations.

Blobs, Tables and Queues (oh my…)

Judging by how often they’re mentioned in the articles I’ve read, these three features seem to be what Microsoft deem the most valuable. All three will play their part in a highly scalable application, which is one of the advantages of the platform. Blobs can be leveraged to provide resources (images, downloads and the like) through a Content Delivery Network, accessed via a REST API – this is very relevant to a CMS, so I’ll definitely be taking advantage of this feature.

Table storage is a document-oriented non-relational database in the same vein as MongoDB or CouchDB. While I imagine the application will use relational databases, hopefully there will be an opportunity to use Table storage; perhaps to hold the content itself. I don’t have a lot of experience with this type of database so it’ll be a good chance for me to learn something.

Queues are very exciting; a built-in way to pass processor-heavy tasks off to worker machines. I can immediately think of a few ways a CMS could make use of this feature: generating PDFs of pages; creating ZIP files of multiple downloads; analysing uploaded files for automated tagging and classification; computing internal analytics… there are plenty of scenarios where queuing could be invaluable. This feature interests me the most.

SQL Azure

Microsoft have provided SQL Server support, albeit in a modified fashion, through SQL Azure. I’ve used SQL Server frequently over the last 4 years but have always preferred to use MySQL since until recently it’s been better supported by PHP through both highly maintained PDO drivers, and the mysqli client library. That has changed in the last year or so with Microsoft’s SQL Server Driver for PHP, and this will be my first chance to make use of that driver. It’s likely that I’ll employ Doctrine 2′s database abstraction layer since it has support for the driver, and it’ll make my application more portable in future – plus I’ve been looking for an excuse to put Doctrine 2 through its paces, having used Doctrine 1 extensively.

Windows Azure Platform Appfabric

Appfabric is a substantial element, comprising many components including Access Control, Caching, and Service Bus, which allows applications and services to communicate even through restrictive firewalls. Access control is a way to perform user authentication through federated identity services such as Active Directory, Microsoft Live, Yahoo!, Facebook and Google, which will be useful to web 2.0 style social applications that often delegate user identification. If it’s straightforward enough to do (and Microsoft say that it is) I may manage user authentication in this way; the web certainly doesn’t need another authentication device.

I’m unclear as to whether the caching system can currently be used; this article mentions only .NET applications, and suggests that it is only available for preview, which is a shame. If it isn’t, then there are other options available for caching – simple file-based caching, which will probably be too slow (and isn’t very scalable); the Wincache extension, which uses shared memory, which will be faster; or perhaps I’ll be able to implement a Memcached solution.

While I think Service Bus is a neat idea, I’m not sure whether my application will require communication with other network devices – it seems to be more relevant to applications concerned with restrictive networks.

Conclusion

I’ve read plenty about Windows Azure this week, and am quite excited about what it can offer a PHP application; some of the features make it almost too easy to dream up application functionality! Next I need to design my application, and get my development environment set up to work with Azure and its tools.

Entering the PHP on Azure contest

I’ve decided to enter the PHP on Azure contest that’s being organised by PHP Benelux and supported by Microsoft, which is challenging developers to build a PHP application that runs in and takes advantage of the Windows Azure platform, Microsoft’s recent cloud computing offering.

While I wouldn’t grumble if I won a trip to Las Vegas for MIX2012 (the first prize), my main motivation for entering is to see how the platform can engender scalability in a web application, since that’s a subject close to my heart. I’m also hoping to use it as an excuse to experiment with some cutting-edge libraries and frameworks in PHP like Doctrine 2, and maybe in JavaScript, like ExtJS 4. I’m thinking the contest rule of regular blogging about my experiences of the Azure platform will help me maintain this blog a little better, too.

So ideally I’ll be blogging about the contest here, and tweeting about it, until it closes on May 15th.

Sending emails with PHP using Swiftmailer and SMTP on Mac OSX

I’m a fan of Swiftmailer for sending emails through PHP – it’s a much more elegant alternative to the mail() function and recently was absorbed into the Symfony project, so its future seems certain. A big plus is its support for sending mail using the SMTP protocol, which makes it great for more complex scenarios where authentication or performance are concerns.

Up until this week I’d only used Swiftmailer on Windows, with an SMTP server on our network. This changed when I needed to do a demonstration using my Macbook, and as OSX comes installed with Postfix I thought everything should just work if I configured Swiftmailer to use an SMTP server on localhost at the standard port (25). This was nearly the case – as I read here while Postfix is installed, it’s not enabled by default. After following the steps outlined there email started sending as expected.