Logo

Maarten Balliauw {blog}

ASP.NET, ASP.NET MVC, Windows Azure, PHP, ...

About the author

Maarten Balliauw is currently employed as .NET Technical Consultant at RealDolmen. His interests are mainly web applications developed in ASP.NET (C#) or PHP and the Windows Azure cloud platform.
More about me More about me
Send mail E-mail me


ASP.NET MVC Quickly Subscribe to my RSS feed Follow me on Twitter! View Maarten Balliauw's profile on LinkedIn
View Maarten Balliauw's MVP profile

Search

Latest Twitter

    Follow me on Twitter...

    Archive

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

    © Copyright Maarten Balliauw 2012


    Accessing Windows Azure Blob Storage from PHP

    Pfew! A week of Microsoft TechDays here in Belgium with lots of talks on new Microsoft stuff, Azure included. You may know I already experimented with Windows Azure and ASP.NET MVC. Earlier this week, I thought of doing the same with Windows Azure and PHP...

    What the ...?

    imageAt Microsoft PDC 2008, the Azure Services Platform was announced in the opening keynote. Azure is the name for Microsoft’s Software + Services platform, an operating system in the cloud providing services for hosting, management, scalable storage with support for simple blobs, tables, and queues, as well as a management infrastructure for provisioning and geo-distribution of cloud-based services, and a development platform for the Azure Services layer.

    You can currently download the Windows Azure SDK from www.azure.com and play with it on your local computer. Make sure to sign-up at the Azure site: you might get lucky and receive a key to test the real thing.

    And what does PHP have to do with this?

    As a reader of my blog, this should not be a question. I'm on the thin line between the Microsoft development environment (.NET) and PHP development environment, and I really like bridging the two together (think PHPExcel, PHPLinq). And cheap, distributed hosting of data (be it file or databases) is always interesting to use, especially in web applications where you may store anything your users upload. I have created a Zend Framework Proposal for this, let's hope this blog post ends as a contribution to the Zend Framework.

    Show me the good stuff!

    Will do! Currently, I have only implemented Azure blob storage in PHP, so that's what the following code snippets will be using. Enough blahblah now, here's how you connect with Azure:

    $storage = new Zend_Azure_Storage_Blob();

    This actually sets up a connection with the local Azure storage service from the Windows Azure SDK. You can, however, also pass in an account name and shared key from the real, cloud hosted Azure, too. Next: I want to create a storage container. A storage container is a logical group in which I can store any data. Let's name the container "azuretest":

    $storage->createContainer('azuretest');

    Easy? Yup! Azure now has created some space on their distributed storage for my files to be dumped in. Speaking of which: let's upload a file!

    $storage->putBlob('azuretest', 'images/WindowsAzure.gif', './WindowsAzure.gif');

    There we go. I've uploaded my local WindowsAzure.gif file to the azuretest container and named the file "images/WindowsAzure.gif'". Don't be confused: it is NOT stored in the images/ folder (there's no such thing on Azure), this is really the full filename. But don't worry, you can mimic a regular filesystem with folders, for example by retrieving all files that are prefixed with "images/":

    $storage->listBlobs('azuretest', '/', 'images/');

    Piece of cake!

    I wanna play!

    Sure, who doesn't? Here's a preview of the classes I've been creating: Zend_Azure_CTP.zip (11.51 kb)

    Now let's hope my Zend Framework Proposal gets accepted so this can be a part of the Zend Framework. In the meantime, I'll continue with this and also implement Azure table storage: cheap, distributed database features in the cloud.

    kick it on DotNetKicks.com


    Comments (3) -

    B Waters United States |

    Tuesday, April 21, 2009 6:37 PM

    B Waters

    As a non MS developer I am fnding it a bit hard to get a handle on the lines between azure and live services.... would you library for example let me also put and get a 'file'/blob from the live skydrive programatically?

    Maarten Balliauw Belgium |

    Tuesday, April 21, 2009 10:18 PM

    Maarten Balliauw

    No, that's something different unfortunately. Live skydrive is more for personal use too, where Azure storage is reaklly to be used for application storage.

    Abdul Jaleel Kavungal Kunnumpurath India |

    Saturday, April 16, 2011 6:10 PM

    Abdul Jaleel Kavungal Kunnumpurath

    Here is a full detailed presentation on how to setup wordpress on Windows Azure  cloudgeist.blogspot.com/.../...ess-on-windows.html

    Pingbacks and trackbacks (2)+

    Comments are closed