Friday, 26 April 2013

Accessing Azure Role Configuration from PHP

This should be a simple thing, Azure recommends using Azure shared configuration for your instances which allows not only the values of these items to be hidden from PHP/.Net code but also allows them to be changed on the fly. How do you read them from PHP?

Firstly, the configuration items are declared in the .csdef and .cscfg in exactly the same way as they are in .Net. They can be given values in the cscfg files or left blank and set after deployment if that floats your boat.

You would think that you can just go and get which is the latest MS library for PHP Azure but for reasons which I can only assume are related to drink and drugs, it does not support access to the Role Environment of Azure where the configuration settings live.

Do not cry, just download the older (deprecated!) version that the MS one is based on from and then once you have added this to your project in whichever way you fancy, use the following simple expression to get the value of a configuration variable from the Role Environment:

$myVariable = Microsoft_WindowsAzure_RoleEnvironment::getConfigurationSettingValue('ConfigItemName');

Easy as pie.
Post a Comment