Windows Azure SDK for PHP – ‘PartitionKey’ property value must satisfy is_string.

When building out an application there are many factors you need to consider, these considerations boil down to functional and non-functional requirements that you as a developer or architect are set out to achieve. In many circumstances, if not all, we are accepting data as an input from a user or other medium, transforming or normalizing that data into something that will help fulfill other requirements of an application.

In order to fulfill scalability goals it may be necessary to find alternative means to traditional storage, something that was designed with scalability in mind. One such service is Windows Azure Table Storage which is defined as:

[Windows Azure Storage] Tables offer NoSQL capabilities for applications that require storage of large amounts of unstructured data. Tables are an ISO 27001 certified managed service which can auto scale to meet massive volume of up to 100 terabytes and throughput and accessible from virtually anywhere via REST and managed API’s.

The topic of Windows Azure Storage Abstractions and their scalability targets is some what out of scope of this post, however, keep in mind that it is important to understand the Windows Azure Storage Architecture and more specifically How to get the most out of Windows Azure [Storage] Tables.

Integer values for PartitionKey or RowKey with PHP

If you’ve done your research on designing for scale with Windows Azure Storage and you find that Integer values are what you need for your specific data model, keep in mind that PartitionKey and RowKey values are of type string.

While this doesn’t seem like a foreign concept you may find yourself in a situation where you have an error while attempting to use integers as strings while interacting with the Windows Azure SDK for PHP. The error you will receive is “PartitionKey [or RowKey] property value must satisfy is_string”. In my particular scenario I was loading my tables by iterating through an array of key/value pairs.

My array looked like this:

In which you may expect the key to be treated as a string, which isn’t the case. To understand the reasoning behind this, we’ll go right to the source.

The key can either be an integer or a string. The value can be of any type.

Additionally the following key casts will occur:

  • Strings containing valid integers will be cast to the integer type. E.g. the key "8" will actually be stored under 8. On the other hand "08" will not be cast, as it isn’t a valid decimal integer.
  • Floats are also cast to integers, which means that the fractional part will be truncated. E.g. the key 8.7 will actually be stored under 8.
  • Bools are cast to integers, too, i.e. the key true will actually be stored under 1 and the key false under 0.
  • Null will be cast to the empty string, i.e. the key null will actually be stored under "".
  • Arrays and objects can not be used as keys. Doing so will result in a warning: Illegal offset type.

According to the documentation, you’ll notice that “strings containing valid integers will be cast to integer type”, in order to ensure that the now converted integer is provided to the service proxy as a string, we need to call strval() on the key when providing it as a PartitionKey or RowKey. To provide an example of this consider the following:

Where addEntity() constructs an entity and inserts it into Windows Azure Table Storage.

Conclusion

In this post I clarified a potential issue that may arise when iterating over an array with key/value pairs to push entities into Windows Azure Table Storage.

Stay Cloudy My Friends…

Windows Azure Training Kit Update Released – August 2012

Today, My team has released a new drop of the Windows Azure Training Kit, it’s available for download now!

What is the Windows Azure Training Kit?

The Windows Azure Training Kit (WATK) is one of the best ways to learn, practice or teach how to leverage Windows Azure and it’s supporting services.

Official Description

Windows Azure Training Kit includes a comprehensive set of technical content to help you learn how to use Windows Azure.

What’s new in the Windows Azure Training Kit?

This release [August 2012] of WATK includes 41 hands-on labs and 35 presentations.

Hands-on Labs

We have pulled in some changes from our GitHub Repository and addressed a number of bug fixes for our hands-on labs for this release. Feel free to Report Issues if you run across a problem in a hands-on lab or presentation.

Presentations

This release introduces a new agenda for Windows Azure DevCamps which contains 7 new presentations:

  • DevCamps Keynote
  • DevCamps Websites
  • DevCamps Cloud Services
  • DevCamps Virtual Machines
  • DevCamps Data
  • DevCamps Windows 8 + Windows Azure
  • DevCamps Windows Phone + Windows Azure

In addition to the new agenda, the following presentations were added to the foundation agenda:

  • Security & Identity
  • Building Scalable, Global and Highly Available  Web Apps
  • Windows Azure SQL Database
  • Windows Azure SQL Federations
  • Windows Azure Reporting
  • Windows Azure Data Sync

Have any feedback?

I’d love to hear any feedback that you have in regards to our training kit. Please leave a comment below.

Stay Cloudy my Friends…

Workaround for Deleted Folder Still Exists in Windows Azure Web Sites

Depending on how much you’ve been experimenting with your 10 Free Windows Azure Web Site accounts you may come across an issue when deleting then immediately recreating a folder. I noticed this issue when upgrading to the recently refreshed Windows Azure Storage for WordPress Plugin.

WAWS-Deleted-folder-still-exists

 

 

 

 

 

Workaround: Stop/Start your Web Site

In order to work around this, I did a quick Stop/Start on my Windows Azure Web Site. There are a two ways in which you can Stop and Start your Web Site, first, the Windows Azure Management Portal, second, the Cross Platform Command Line Tools.

Stop/Start a Web Site from the Windows Azure Portal

  1. Login to the Windows Azure Management Portal.
  2. Click on Web Sites in the left hand menu.

    image

  3. Select a Web Site from the list.
    image
  4. Click Stop from the bottom control bar.
    image
  5. Click Start from the bottom control bar.
    image

Stop/Start a Web Site from the Cross Platform CLI Tools

  1. Follow the instructions on How to install the Windows Azure Command-Line Tools for Mac or Linux (they work on Windows too!)
  2. Follow the instructions on How to download and import publish settings.
  3. Execute azure site stop 'site-name'.
  4. Execute azure site start 'site-name'.

After Stop/Starting your website you should be able to recreate the folder which was previously deleted.

Happy Clouding!

Update Released: Windows Azure Storage Plugin for WordPress

Microsoft Open Technologies, Inc. announced today that they have released an update to the existing WordPress Plug-in, Windows Azure Storage for WordPress.

If you aren’t familiar with the tool, essentially it allows you to sign up for Windows Azure, create a storage account and save your blog post assets like images, videos and documents in a durable, CDN enabled [enabling CDN in Windows Azure Storage] storage system with up to 100TB of storage!

Why Update the WordPress Plug-in?

The major reason for the update was to bring the tool inline with the most recent release of the Windows Azure SDK for PHP [Windows Azure SDK for PHP on GitHub]. For this reason alone, it is a great example of a real world application which reaches thousands of users [Current Downloads as of this post: 2635].

Need Installation Instructions? Read Windows Azure Storage Plug-in for WordPress Updated by Brian Swan.
Need a Blog? Sign up for a Free Windows Azure Account, then Setup a new WordPress Blog on Windows Azure Web Sites using the OSS Gallery.

If you use WordPress as your blog engine or as a CMS, the Windows Azure Storage for WordPress Plug-in is definitely worth a look.

How does the Plug-in Work?

More interested in the Architecture of the Plugin? Read Windows Azure Storage Plug-in for WordPress by Doug Mahugh

The plug-in uses the WordPress Filters to inject new storage functionality such as a tab for accessing existing items in the storage container, a mechanism for saving content to Windows Azure Storage, as well as providing XML-RPC support for saving attachments from third party blog tools (like Windows Live Writer).

Under the covers the tool saves your media files as Block Blobs, it utilizes the BlobRestProxy exposed by the Windows Azure SDK for PHP to commit the files in individual blocks (max. 4mb in size) before committing the entire blob. The benefit to using this technique is if any one (or multiple) block doesn’t succeed in uploading, the maximum amount of data that needs to be resent to Blob Storage is reduced (which in turn saves in bandwidth usage).

All thumbnails which are auto-generated by WordPress are uploaded in the same fashion, then the metadata (Container Name, Blob Name, Thumbnail urls) are all saved to the database using add_post_meta.

Can I Contribute?

If you want to add additional features, or view the Source code for the Windows Azure Storage for WordPress Plugin it is available from the WordPress Plug-ins SVN Repository under a New BSD License.

More into Git? [Me too…] Instructions for Bidirectional operations between SVN and GIT

Once you’ve downloaded the source, you may want to consider checking out WebMatrix which has support for PHP syntax highlighting and code completion, as well as WordPress specific code completion which will be helpful when you’re extending the plug-in.

Happy Blogging!

Using WebMatrix to Develop Apps with PEAR Modules

If you’re developing PHP on Windows, Microsoft has an IDE that may be of some interest to you, it’s called WebMatrix. WebMatrix is an extremely powerful IDE providing code highlighting for PHP, Node.js, ASP.NET Razor, it even offers code completion for popular OSS CMS platforms like WordPress, Drupal and Joomla. Unlike conventional IDE’s it’s extremely lightweight, despite it’s heavy hitting features.

One of the oddities of WebMatrix is that is installs it’s own copy of php on your system located in C:\Program Files (x86)\IIS Express\PHP. Normally not a big deal, however if you start building larger applications you’ll probably want to include some functionality which will require a Pear package. This isn’t as straight forward as one would hope.

Installing Pear in WebMatrix

Before I send you down a wild goose chase, you can validate that WebMatrix is actually using the php.ini file from it’s own installation, you can do this by including <?php phpinfo(); ?> in one of your php files then run the site. I have also assumed that you have already installed Pear using the instructions.

When the PHP Information loads you’ll want to check two of the variables first check Loaded Configuration File this will tell you the path of the php.ini file it is reading the configuration information from. Second, you’ll want to check out include_path which will print out the include paths that it will check for addition application code blocks, such as Pear Packages by default this will be .;C:\php\pear.

Finding the Pear directory on your machine

To find the path to Pear on your machine open up the command prompt and type pear config-get php_dir, copy the path that is outputted and close the window.

In order to change the php.ini file, you’ll need to open Notepad with elevated permissions this is due to the file being contained in the Program Files directory which is protected by the Operating System.  Once you have opened the WebMatrix php.ini file from C:\Program Files (x86)\IIS Express\PHP\v5.3 scroll to the bottom of the file and add include_path=".;C:\Path\From\Pear\Config\Output\"

Oh Great, I did all that and it still doesn’t work

Before you go and brush your shoulders off, you need to restart IIS Express. The php.ini file is only loaded when the IIS Express process is started, there is no file system watcher set up to monitor changes to the php.ini file.

Restart IIS Express by clicking on the blue circular arrow (marked restart) in the Sites tray of the WebMatrix Home Ribbon.