Windows Azure Websites PHP: Cache Service via Memcache

I've been migrating a PHP application to Azure Websites which uses memcached extensively. You can connect to Azure Cache Service (still in the preview program) using the memcache protocol, effectively making the migration seamless from an application point of view. I couldn't find much out there on how to enable this PHP extension in Azure Websites, so I thought I'd write up the steps I followed. First, open up the configure tab of your Azure Website. Take special note below of your PHP version and platform - you'll need both to determine which version of the memcache extension

Check version and bitness

Based on the above, download the extension DLL from here - make sure you grab the NTS (non thread safe) version: http://pecl.php.net/package/memcache/3.0.8/windows You might also want to check this page to make sure you're grabbing the latest version available http://pecl.php.net/package/memcache Your downloaded file should look something like this: php_memcache-3.0.8-PHP_VERSION-nts-vc9-PLATFORM.zip. Extract and upload the DLL to your site root using your chosen deployment method for the site (source control, dropbox, FTP etc). A fairly common recommendation is to place these PHP extensions in a folder called "bin", which automatically protects them from being downloaded by the outside world over HTTP. Scroll down on the configure tab until you see app settings. Here, we configure PHP to look for your extension DLL by adding a variable called PHP_EXTENSIONS and pointing it to your uploaded DLL:

app settings php extensions

Save, and you should be good to go! You can verify this by creating a PHP file in your site with the following... <?php phpinfo(); ?> ...and then viewing that page in your browser:

memcache result

A quick last tip - you can easily add multiple PHP extensions this way. In your PHP_EXTENSIONS app settings variable, just separate the DLL names by commas. I'll be following this post up with a way to do this for all your sites without needing to upload the DLL into each one individually. Have fun and good luck!

Tweet