Note:This article pertains to the CodePlex SDK initially released late 2009. The Windows Azure team has since then released a newer version of the Azure SDK for PHP on Github. Please refer to the Windows Azure PHP Developer Center for documentation on this more recent version of the SDK.
Please stay tuned and come back here regularly as we are working on refreshing the tutorials to deliver up to date and useful content for our PHP developers.
The Windows Azure Service Configuration file is a powerful place to store configuration information about your service and application. For example, if you need to determine your storage configuration settings and do not want to create an additional spot in code to keep updated or you want to change an application variable on the fly that will be instantly picked up by all instances without redeploying then this method is for you.
In this tutorial you will learn how to use the php_azure.dll PHP module to tap into the Windows Azure platform and read values from your Service Configuration file.
Download the php_azure.dll PHP module
The php_azure.dll is an add-on module for PHP. Since it is an add-on it is not available with the default PHP installation package. Head out to the project page on CodePlex and download the latest version
There is also some valuable information on the documentation page regarding additional features of the module.
Using the module
The php_azure.dll module needs to be present in your Windows Azure project to use it. The simplest way is to add the module to your scaffold before creating the package for upload.
Create a project using the DefaultScaffolder scaffold
If you already have a project from a scaffold you should skip this step and move to Add the module to your project, however keep in mind this tutorial uses a sample project at C:\temp\phpAzureModule and adjust your paths accordingly.
For the purposes of this tutorial a sample project will be created in C:\temp\phpAzureModule.
- Open a Windows Azure SDK Command Prompt from the Start menu
- Create the new project with the following command:
scaffolder run -out="C:\temp\phpAzureModule"
Add the module to your project
In your project will be a folder for a web role and inside that folder you will find a php folder. This php folder can be used to provide custom extensions and php.ini settings to your deployment. There are two simple steps to adding the php_azure.dll module to your project:
- Copy the php_azure.dll file you previously downloaded to the ext folder inside the php folder. This will be located at: C:\temp\phpAzureModule\PhpOnAzure.Web\php\ext
- Update the php.ini file to enable the php_azure.dll on
your PHP installation. This file is located at
will need to insert the following line at the bottom of the
Now save the php.ini file and you will have access to the Service Configuration information from your PHP application.
How to read Service Configuration values
After the php_azure.dll module is installed a new function, azure_getconfig($setting) , will be available. From anywhere inside of your PHP application you will now be able to use this new function.
For example, in your Service Configuration you may have a setting called StorageAccount that contains the connection information for your Windows Azure storage account. To access that value in PHP you would use the following code:
$StorageAccount = azure_getconfig('StorageAccount');
At this point you should be able to read the values from your Service Configuration on Windows Azure. This can be highly beneficial as storing values in the Service Configuration allows you to make quick and easy on the fly changes to settings that will instantly alert all running roles and cause them to adjust accordingly.
For more information see the project documentation page on CodePlex