Accessing ServiceConfiguration in FastCGI (PHP) web role
Edit on GitHubWhile 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.
[code:c#]
$appName = azure_getconfig(“AppName”);
$storageAccount = azure_getconfig(“StorageAccount”);
// etc.
[/code]
Next to this, logging is now also exposed: simply call azure_log() and you’re done:
[code:c#]
azure_log(AZURE_LOG_INFORMATION, “This is cool!”);
azure_log(AZURE_LOG_CRITICAL, “Critical errors are not cool…”);
// etc.
[/code]
Oh, you want to have the path where a localStorage is available? (see here for info)
[code:c#]
$rootPath = azure_getlocalresourcepath('teststore');
$pathMaxSizeInMb = azure_getlocalresourcepathsize('teststore');
// etc.
[/code]
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
Downloads
- 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)
Resources
The following links have been helpful in developing this:
- http://blog.slickedit.com/2007/09/creating-a-php-5-extension-with-visual-c-2005/
- http://blog.harddisk.is-a-geek.org/index.php/dev/php/php-on-windows/
- http://ishouldbecoding.com/2008/03/08/custom-building-php-on-windows-and-linux
- http://www.php.net/extra/win32build.zip
- http://devzone.zend.com/node/view/id/1021
- http://devzone.zend.com/node/view/id/1022
- http://devzone.zend.com/node/view/id/1024
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.
0 responses