Fix for WordPress Plugin Update Issues on Windows Azure Web Sites

Good News!

In a recent service update to Windows Azure Web Sites, the Windows Azure Web Sites team has updated the version of Wincache for PHP 5.3 sites to WinCache 1.3.4, which resolves this issue!

Screen Shot 2013-04-04 at 8.58.48 AM

Screen Shot 2013-04-04 at 8.58.19 AM

A while back I posted an article called Workaround for deleted folder still exists in Windows Azure Web Sites, which talks about how to get around an issue specifically with WordPress plugin upgrading. Recently, on twitter there have been a few people running into this issue, so I thought I would go into a little bit more detail on the issue and how to work around it, permanently.

The Cause of the WP Plugin Issue

In order to dig to the root of the problem, let’s take a few steps back here and get a little bit better of an understanding of the different pieces at play.

PHP

PHP is an interpreted language, simply put it is not compiled into machine code, but instead read and executed step-by-step by an interpreter in this instance, the PHP runtime.

This means that every line would need to be read, interpreted and executed on each request. Which in computer science we understand is not very efficient. For this reason PHP can employ caching to avoid parsing every instruction on each request, instead it stores a certain amount of interpreted instructions in shared memory.

IIS

It’s no secret that Windows Azure Web Sites leverages IIS as it’s Web Server. IIS uses FastCGI to interact with the PHP Interpreter. With the Web Server being able to interact with an interpreter, we have the means to serve up PHP code on IIS. As stated above, PHP can leverage a cache in order to avoid parsing each line of a script, enter WinCache.

WinCache

WinCache is installed and enabled by default for PHP Runtimes maintained by the Windows Azure Web Sites team.

WinCache is a caching system which can be enabled for PHP application which run on Windows  leveraging IIS. This is done by Installing WinCache, then adding a reference to php_wincache.dll from within your php.ini file.

 

By default, Windows Azure Web Sites has PHP 5.3 installed with WinCache 1.1.

Now that we have a better understanding of the different pieces involved, let’s take a closer look at the issue at hand.

There is a bug in WinCache 1.1 [Bug #59352] which causes a lock on a folder which isn’t released until IIS is restarted, which is why this workaround is effective at fixing the issue.

How to Resolve the Plugin Updating Issue

The resolution is fairly simple. The bug has been fixed in a newer release of WinCache (version 1.3 which works with PHP 5.4).

Recently, PHP 5.4 was enabled in Windows Azure Web Sites making the fix as simple as following these steps to Enable PHP 5.4 in Windows Azure Web Sites.

Happy Coding!

PHP 5.4 Now Native in Windows Azure Web Sites

A while back I wrote a blog post on Enabling PHP 5.4 in Windows Azure Web Sites, when we enabled the ability to bring-you-own-runtime to Windows Azure Web Sites. This is still a valid solution if you would like to manage your own PHP.ini file, or if you would like to ensure that you are using a specific build of PHP.

It’s exciting to announce that Windows Azure Web Sites now has PHP 5.4 ready to be enabled in your Web Sites.

Even though PHP 5.4 is available PHP 5.3 is still enabled by default.

image

Enable Native PHP 5.4 in Windows Azure Web Sites

After Creating a Windows Azure Web Site, navigate into the Web Site details page and select the CONFIGURE tab. Under the framework section you will see PHP VERSION, select the box containing 5.4, it will turn purple notifying that there is an unsaved change.

image

At the bottom of the browser viewport you will find the TASK DRAWER, which would have changed to include a SAVE button. Click the SAVE button to enable PHP 5.4 for your Windows Azure Web Site.

image

Once the change has been saved, you’ll be greeted by this nice little success notice.

image

Finally, you will also notice that the purple indicator has now changed back to blue on the PHP 5.4 box.

image

You are now ready to deploy PHP 5.4 applications to Windows Azure Web Sites.

Happy Clouding!

Enabling PHP 5.4 in Windows Azure Web Sites

Much like many other developers, I like to live on the bleeding edge, learning new language features, using the latest tools so naturally one of the things I wanted to see in Windows Azure Web Sites is support for PHP 5.4. I’m pleased to be telling you today in this post that support for Bring-Your-Own-Runtime is now available in Windows Azure Web Sites.

Out of the box, Windows Azure Web Sites supports PHP 5.3 as you can see from the snapshot of the portal below. In this article I’ll explain how to enable PHP 5.4 in Windows Azure Web Sites.

Windows Azure Framework Support

Configure PHP 5.4 Handler Mapping in Web Sites

In order to enable support for PHP 5.4 in your Windows Azure Web Site, you will first need to create a Web Site.

If you haven’t already signed up for a Windows Azure account, get a 90 day free trial of Windows Azure which gives you access to 10 free Windows Azure Web Sites.

To create your first site, I would suggest following one of the many tutorials on the Windows Azure PHP Developer Center.

I’ve created my Windows Azure Web Site, What’s Next?

To bring you up to speed, I’ve created a Web Site using Quick Create, using configphp54 as the dns prefix for my Web Site.

Web Sites
Click on the Name of the Web Site [in my case configphp54] to proceed to the Details page for your site. On the details page you will see top level navigation items [DASHBOARD, MONITOR, CONFIGURE, SCALE, LINKED RESOURCES] listed. Click on DASHBOARD.

In order to be able to deploy files to the site, we’ll need to create some deployment credentials, you can create [or reset] your deployment credentials from the quick glance section of the DASHBOARD.

image

Click on create [or reset] deployment credentials to be prompted with a dialog box to enter your credentials.

image 
Fill out the user name, new password and confirm password to create your deployment credentials or simply the new password and confirm password to reset your password. Now your web site is ready for FTP or Git deployment.

Next, click on CONFIGURE.

At the bottom of the CONFIGURE page you will see a new section called Handler Mappings.

image 
Handler Mappings are a way to map a Fast-CGI script processors to file extensions in IIS. These script processors are typically console applications which means they may be able to accept additional command line switches. To set up a custom handler mapping you are required to set at least 2 of the three values, let’s quickly go into some more details around Extension, Script Processor Path and Additional Arguments.

Extension: This is the file extension which should be mapped to the Script Processor.

Script Processor Path: This is the field which specifies the absolute path to a Script Processor [in our case this will be php-cgi.exe]. The script processor’s binary and configuration files can be located anywhere within the application root directory which can be accessed using the D:\home\site\wwwroot path.

Additional Arguments: If the script processor supports additional command line switches which you may require, you can configure them in the Additional Arguments input box.

We’re only going to fill out the Extension and Script Processor Path to configure PHP 5.4. Enter the following values into the handler mappings section.

Note

After you type each line, click the checkmark at the end of the line to commit the value and add a new row. Clicking on the checkmark does not save the entries, a save button will show up in the command bar at the bottom of the portal.

Extension

Script Processor Path

Additional Arguments

*.php

D:\home\site\wwwroot\bin\php54\php-cgi.exe

Warning

wwwroot is publicly exposed to the internet which could potentially allow remote execution of executable files contained in wwwroot. By default IIS blocks access to the bin directory of any website or virtual directory, which is why it is safe to place the php runtime in the wwwroot/bin directory.

After you are finished, hit the save button that appears in the command bar to commit these settings.

Wait? Where do I get PHP 5.4 for Windows Azure Web Sites?

Before this site will actually work, we need to provide the php54 runtime in the path specified in our handler mappings settings. Download and extract the VC9 x86 Non Thread Safe zip file to the bin directory in your project

Note Your password is the password you typed while creating your deployment credentials above. This password is used for Git or FTP deployment. For WebMatrix, you can use the Publish Profile to load the configuration for a seamless publish experience.image

Trust, but Verify… (Thanks Horatio… Yeah!)

Upload an index.php file which contains a call to phpinfo() to the wwwroot folder.

If you browse to the site you will see that the site is in fact running with the latest version of PHP (5.4.7 at time of writing).

image

PHP does auto-discovery of the php.ini file by looking in known locations where it is expected to be placed, the first such place it looks is the directory which contains the script processor. This means that you will have access to your own php.ini file.

image

By Default, the PHP runtime does not have a php.ini file, it is packed with php.ini-development and php.ini-production. Rename php.ini-production to php.ini, open the file and search for fastcgi.logging and remove the preceding semicolon (;) which will uncomment the line fastcgi.logging=0. FastCGI Logging needs to be disabled (0) in the pipeline or it will return a HTTP 500 when you attempt to execute a script.

With Great Power, Comes Great Responsibility

Now that you own the runtime, you essentially own the experience and the security of the application. Be sure to follow the guidance on iis.net Best Practices for Configuring FastCGI and PHP to ensure optimal performance and security.

Stay Cloudy my Friends

WebMatrix 2: Available at a Web Platform Installer Near You

WebMatrix v2  hits the shelves yesterday so run out and download it now!. There are many additions to WebMatrix in this launch and I would like to take the time to describe a few of the things that may shock and excite you.

If you aren’t familiar with WebMatrix here is a quick blurb from the product page:

WebMatrix is a free and lightweight web development tool.
Create, publish, and maintain your website with ease.

What is new in WebMatrix 2?

It’s incredible how many features they can plug into WebMatrix and still have it be very lightweight and simple to use. Let’s take a look at some of the newly supported features of WebMatrix 2.

Intelli-Sense & Syntax Highlighting

Ok, so this might not necessarily be *new* to WebMatrix, but it has definitely been expanded. Many of you may be asking, what the $#@! is Intelli-sense? Intelli-sense is autocomplete on steriods, not only does it list the options for what you are currently typing, but it provides information around if what you’re typing is a method, constant or other variable type, it will also provide you with the method signature or additional information about the particular item you have selected in the list. There is intelli-sense and syntax highlighting support for the following languages/frameworks:

  • HTML5
  • CSS3
  • Node.js
  • PHP
  • ASP.NET MVC
  • Javascript
    • WordPress
    • Joomla!
    • Drupal
    • LESS
    • SASS
    • jQuery Mobile

    Yeah, WordPress, Drupal and Joomla! support, WebMatrix is making it easier to extend your favourite Open Source CMS by providing a quick reference to the built in methods of these framework applications.

    Community Oriented

    Now for something everyone can enjoy!

    Web Gallery

    Install a wide variety of Open Source projects directly from the Web Gallery including WordPress, Joomla!, Drupal and phpBB. New items are added to this list on a regular basis, so it could also be a great tool to discover new Open Source Projects.

    WebMatrix-Community

    Extension Gallery

    Another cool community aspect of WebMatrix is the extension gallery, which allows you to build custom extensions to WebMatrix. The extension gallery is already chalked full of great extensions including Git for WebMatrix, iPhone, iPad & Windows Phone Simulator.

    Mobile Friendly

    Mobile is all the rage right now, so having a tool not only helps you test on mobile device emulators, but actually gets you started with Mobile Friendly Templates and has auto completion for jQuery mobile, it’s like a match made in heaven.

    Cloud Friendly

    Last but definitely not least, the one thing you most likely come to my blog for, THE CLOUD! WebMatrix allows you to deploy to Windows Azure right out of the box. Of course this isn’t the only deployment option, but quite frankly, it’s the only deployment option I’ll be using. Within a few steps you can be publishing an existing site from your hard drive to Windows Azure Web Sites, or pull down that WordPress site you installed using the Windows Azure Gallery for a few quick changes.

    To Learn more about the cloud features, read Announcing WebMatrix 2 by Jonathan Guerin.

    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…

    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!