Accessing ServiceConfiguration in FastCGI (PHP) web role

Edit on GitHub

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?

kick it on DotNetKicks.com

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

Resources

The following links have been helpful in developing this:

kick it on DotNetKicks.com

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.

Leave a Comment

avatar

0 responses