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!
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).
Automation of tasks is one thing that I am an advocate of in my development projects. Getting functionality that is repeatable with a low risk of human error for a one time cost is a sound business decision and as a developer, keeps your hands on rolling more code for a greater percentage of your work day. It’s a Win-Win scenario.
The Windows Azure Web Sites team along side the Kudu team have added Continuous Deployment functionality in Windows Azure Web Sites with support for three familiar social source code repositories: CodePlex, GitHub and BitBucket. The team has also added support for Contiguous Integration using Team Foundation Service [a new Cloud Based offering of Team Foundation Server].
Windows Azure Web Sites now allows Continuous Deployment from Private Repositories from both GitHub and BitBucket.
NOTE: If you do not need a MySQL database, or have decided to go with another database option, choose Quick Create from the Web Site menu instead of Create with Database.
Associate a Source Code Repository
In order to facilitate the Continuous Deployment it’s necessary to have a centralized location to pull the website code from, in this particular blog entry we’re going to use GitHub and BitBucket.
Initializing a Git Repository will redirect the Management Portal to the DEPLOYMENTS tab.
Now that Git has been enabled use the collapsible menus to select how you would like to deploy code to the new Windows Azure Web Site.
Associate a GitHub Repository to Windows Azure Web Sites
Expand the item labeled Deploy from my GitHub repository.
Click on Authorize Windows Azure. This will open a window to federate with GitHub, you will need to approve the ability for Windows Azure to access your GitHub account.
Once access has been granted, the browser will redirected back to the Management Portal to a screen to select either a Public or Private repository.
After selecting the repository to be published, click on the check mark to start the deployment process.
If your repository is empty, push to GitHub to trigger deployment to Windows Azure.
Each subsequent push to GitHub will trigger a service hook and begin a deployment of the latest bits to the Web Site. Now that the deployment has been pulled into the Web Site, clicking on Browse in the Taskbar Drawer will launch the web application.
Associate a BitBucket Repository to Windows Azure Web Sites
Just like associating a GitHub account to a Windows Azure Web Site, expand the Deploy from my BitBucket repository. Authorize Windows Azure to access a BitBucket account by federating authentication through BitBucket.
After clicking on Authorize Windows Azure, a prompt to authenticate with BitBucket.
After signing into BitBucket a prompt to select the Public or Private repository to deploy to Windows Azure Web Sites.
Unlike GitHub, BitBucket will require you push a change to the repository before the Service Hook will deploy code to the Windows Azure Web Site.
Once a push has been made to the private BitBucket repository, the deployment will be pushed to the Web Site.
In the taskbar drawer at the bottom of the browser viewport, click the Browse Button.
A new window will open and the site will display the web files which were pulled into the Web Site.
Conclusion
Continuous Deployment is a great way to introduce new features or functionality to your customers in an automated fashion. With the new support for Private Repositories, Windows Azure Web Sites can help delivery stunning web sites which utilize either open source projects from public repositories, or provide clients with a customized solution from a private repository.
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.
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.
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.
Once the change has been saved, you’ll be greeted by this nice little success notice.
Finally, you will also notice that the purple indicator has now changed back to blue on the PHP 5.4 box.
You are now ready to deploy PHP 5.4 applications to 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.
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.
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.
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.
Click on create [or reset] deployment credentials to be prompted with a dialog box to enter your credentials.
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.
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.
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).
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.
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.
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.
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.
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.
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.