While working on a sample PHP application hosted on Windows Azure, I found that it is nearly impossible to retrieve information from the Windows Azure ServiceConfiguration.cscfg file. Also, it is impossible to write log messages to the Windows Azure Web Role. Well, both are not 100% impossible: you can imagine dirty hacks where you let a ASP.NET page do something from PHP and stuff like that. But how about a clean solution? How about… A PHP extension module?
I’ll not be going into detail on how this module was built, but there is a native C++ RoleManager implementation in the Windows Azure samples. Using the resources listed below, I managed to create a PHP extension module, wrapping this RoleManager. The result? You can now retrieve configuration values from the ServiceConfiguration.
$appName = azure_getconfig(“AppName”);
$storageAccount = azure_getconfig(“StorageAccount”);
Next to this, logging is now also exposed: simply call azure_log() and you’re done:
azure_log(AZURE_LOG_INFORMATION, “This is cool!”);
azure_log(AZURE_LOG_CRITICAL, “Critical errors are not cool…”);
Oh, you want to have the path where a localStorage is available? (see here for info)
$rootPath = azure_getlocalresourcepath('teststore');
$pathMaxSizeInMb = azure_getlocalresourcepathsize('teststore');
Want to use it in your own PHP applications hosted on Windows Azure?
- Download the php_azure.dll (see below) and make sure you have it in your /path/to/php/ext folder
- Register the extension in php.ini: extension=php_azure.dll
- Compiled THREAD SAFE module php_azure.dll: php_azure-ts.zip (218.48 kb)
- Compiled NON THREAD SAFE module php_azure.dll: php_azure-nts.zip (218.46 kb)
- Visual Studio 2008 project + source code: vsts-php_azure.zip (218.19 kb)
The following links have been helpful in developing this:
This is an imported post. It was imported from my old blog using an automated tool and may contain formatting errors and/or broken images.