Advertisment

PHP Interoperability for Windows AZURE

author-image
CIOL Bureau
Updated On
New Update

BANGALORE, INDIA: Microsoft's Windows Azure is a cloud platform that increases choice for developers and allows them to use PHP — one of the most popular programming languages on the web. The main purpose of Windows Azure is to provide an infrastructure that is robust, reliable, and scalable for hosting Web applications. Development tools like Visual Studio or Eclipse can be used to build applications that run on Windows Azure.

Advertisment

The Windows Azure platform supports Internet protocols like HTTP, XML, SOAP and REST. PHP runs on Azure using FastCGI, and therefore Azure services can be called from other platforms and programming languages like PHP. It is a cloud environment that helps PHP applications to share the stored information with .NET applications and vice-versa.

PHP Tool Kit for Windows Azure

The Open Source PHP Azure SDK (PHP Azure) provides interoperability for PHP application developers to work with Windows cloud services platform. PHP Azure provides a set of PHP classes for HTTP transport, AuthN/AuthZ, REST and Error Management. Windows Azure Tools for Eclipse for PHP Developers enhances cloud interoperability. It enables PHP developers to create Web applications targeting Windows Azure. It includes a Window Azure storage explorer that allows developers to browse data contained into the Windows Azure tables, blobs or queues.PHP Tool Kit for Windows Azure is an open source application that facilitates PHP developers to use ADO.Net Data Services included in .NET Framework.

Advertisment

The Windows Azure PHP tool kit developed on PHP requires the PHP extensions for XML, XSL and CURL to be installed. This can be installed on Windows or Linux operating systems.The way it works is that a PHP proxy file that contains class definitions is generated based on the metadata interpreted by ADO.NET Data Services. PHP client applications can use those classes to access the data service. The PHP tool kit is independent of the .NET framework and communicates with data services using HTTP and XML or JSON. The Tool Kit offers basic authentication mechanism and also has classes that support authentications for developers.

Opportunities for developers

The Fast CGI protocol in Windows Azure hosting environment enables developers to run web applications on Windows Azure that were written using 3rd party programming languages including PHP.

Advertisment

The applications include:

1. Silverlight applications using PHP
2. IE Webslices & accelerators in PHP web applications
3. Microsoft Virtual Earth maps in PHP web applications

Interoperability opens up chances to work on Windows Azure cloud-based applications with other platforms. Now PHP developers have opportunity to work on Microsoft Visual Studio development environment and .NET Framework and they can build scalable applications using their development skills. PHP developers can make use of the tremendous ADO.NET Data Services features and Visual Studio IDE features. They can also use environments like Eclipse. Microsoft's intentions of getting closer to Open Source projects creates a series of opportunities and ideas of interest for the PHP developers and IT professionals. The number of PHP developers that use Windows on development or production environments is significant. Microsoft embracing the PHP community and offering to make use of ADO.NET data services support in Windows Azure platform gives more scope for developers and IT professionals to use Microsoft technologies in terms of cloud computing and interoperability.

Advertisment

PHP application on Windows Azure

To develop PHP applications on Azure using Eclipse, Microsoft has provided Windows Azure tools for Eclipse. For a step by step installation of all pre-requisites kindly refer to
http://www.windowsazure4e.org/download.

Creating PHP Windows Azure Project from Eclipse

Advertisment

Once you get your development environment ready, things are fairly straightforward from then on. You can start creating your first PHP Windows Azure project from Eclipse. For this, open Eclipse and select File->New Project. You will be presented with a window.

The Windows Azure tool for eclipse gives you an easy to use template to get started on your software. Each Windows Azure project would have two components -- the configuration component where you specify a set of configurations including the number of processor cores required for your software and the other being the software package which contains your compiled code.

You can now start building your app like any regular PHP application and once you are ready to deploy the application, you can do so on the local development fabric (simulation environment) by choosing 'Run in Development Fabric', from the 'Windows Azure' menu option.

Advertisment

 
The image shows the Development Fabric UI

To review your application running in your local development fabric, look for the 'Windows Azure icon' in the System tray (bottom right hand corner), and you will find an option 'Show Development Fabric UI' in the context menu.

Connecting to SQL Azure from PHP

Advertisment

If your application requires data storage / retrieval capabilities, you can leverage the features provided in SQL Azure - the relational database in the cloud. The following code snippet is a sample to connect to a SQL Azure instance. The code is similar to what you would use to connect to an on-premise database — the only change required is a connection string change.

include_once "connect.php";
$masterDB = ;
$dbuser = ;
$dbpwd = ;
$conn = sqlsrv_connect($host, array("Database" => $masterDB,
"UID" => $dbuser,
"PWD" => $dbpwd,
"MultipleActiveResultSets" => '0'))
or die("Couldn't connect to SQL Server on $host");
$query = "";
$result = sqlsrv_query($conn, $query);
while ($row = sqlsrv_fetch_array($result, SQLSRV_
FETCH_ASSOC))
echo " - " . $row<"name"> . "
sqlsrv_free_stmt($result);
sqlsrv_close($conn);

Going Live

When you are done with testing your program in the local development fabric and you would want to deploy your application on Windows Azure you can leverage the deployment portal http://lx.azure.microsoft.com/ to deploy your application. You can subscribe for Windows Azure at https://mocp.microsoftonline.com/site/default.aspx. The free 'Windows Azure Platform Introductory Special' gives you free limits for all MSDN premium subscribers to get hands-on with Windows Azure.

tech-news