Advertisment

PHP on Win: The Whys and Wherefores

author-image
PCQ Bureau
New Update

Microsoft has always been known for its very tightly integrated pieces of

software. For instance, if you look at components like ASP.NET, Active

Directory, SQL Server, Exchange and SharePoint, all of these work extremely well

together and provide a whole bunch of services to each other as well as a great

development platform that lets you use and extend the features as you wish.

However, one of the biggest complaints against Microsoft technologies was that

they did not play fair with others' platforms.

Advertisment

The above complaint has been taken quite seriously by Microsoft and when

developing the current version of Windows Server, they did a fairly surprising

turn around. During the development phase for the latest version of Internet

Information Services (IIS) 7.0, they collaborated with developers of PHP — one

of Microsoft's biggest rivals in the Web application platform space and what

they both came up with is an interesting combination of features.

Direct Hit!

Applies To:PHP programmers



USP:
Learn to use put PHP to use on Windows



Primary Link:
windows.php.net



Keywords:
PHP, Windows

PHP has always been possible to run on Windows and IIS. However, it is in

IIS7 that it really shines. Not only is PHP fully compatible with IIS, it also

is a first class citizen in IIS along with Microsoft's own ASP.NET! PHP on

Windows gets a large number of features, and that too for free, that simply do

not exist on other places where PHP can run.

Advertisment

One of the big changes in IIS7 over previous version is the introduction of

what is known as the ASP.NET Integrated Pipeline Mode. This mouthful actually

means that development platforms that integrate into IIS7 (like PHP), gain

access to many of the features of ASP.NET that are now “exposed” as IIS

features. This means that you can actually add a number of features into a PHP

site on IIS7 very easily either using IIS management or an ASP.NET extension.

Let's take a look at a couple of scenarios below to illustrate these points.

Adding Caching to

your PHP application in IIS7.

Let's say you have a large PHP site hosted on IIS7 using the Integrated

Pipeline. You might find that performance of the site is not up to par and might

want to go ahead and do something about it. The very first thing that you might

want to do is introduce caching into the web site so that repeated queries for

the same page (or page signature - that includes queries to the database as

well) are cached on the Web server and does not require a re-generation or round

trip to the database. There are of course ways to achieve this in PHP itself —

either by writing your own (non-trivial) code or by including third party files

or controls and configuring them.

Advertisment

However when working with IIS7, you can go ahead and use the IIS7's built in

Output Caching mechanism that is based on the caching module feature of ASP.NET.

You can either use the IIS7 GUI or add a ASP.NET Web.config file with the

relevant tags to your PHP site. In either case you can select different options

for the cache, timeouts, change monitoring and expiration policy. With a couple

of clicks you can enable your PHP site to get the comprehensive caching features

of ASP.NET without a single line of code.

Creating a

Membership provider to ADS for use in PHP.
Adding a new

connection string to ADS.

Let us take another scenario as well. Consider an enterprise PHP application

that is important for your organization. Since your organization has grown since

the time it was created, you might want to add or change the authorization and

authentication mechanisms in this app. For instance, you might want to use a

database or Active Directory to authenticate users and give different users

access to different areas of the application based on some roles. Again, if you

are running this on the LAMP stack, you will need to code in these changes

yourself — possibly in each page.

Advertisment

In IIS7, performing all of these tasks is simple and can be done without

changing even a single line of code in your PHP application. Simply use the

ASP.NET Membership and Roles modules as part of the IIS7 pipeline. For this, all

you need to do is setup a connection string to the place where your users and

roles are stored (database, ADS, etc.), setup a provider to point to these and

then create a simple ASP.NET page with a Login control on it. You can also

segregate different parts of the site to different users or roles by creating

authorization entries through IIS.

The final example is of diagnosing problems in your web site. IIS7 contains a

powerful tracing and diagnostics feature again taken from ASP.NET that is now

available for PHP as well. You can quickly perform traces on your web site and

get detailed diagnostic information regarding performance and failures and use

these to troubleshoot your site.

IIS7 comes with more than 40 such features built in. You can also download a

whole bunch of more modules (such as ad management, stop hot linking, URL

rewriting, media streaming and many many more) from the Internet or write your

own using the SDK. Getting access to the extremely rich and powerful feature set

of ASP.NET without having to recode your own PHP pages is also a great benefit

that clearly puts the advantages of using PHP on Windows 2008 in front.

We'll continue this series with some other explorations — such as benchmarks

of PHP applications running on different platforms as well as a look at the TCO

of these cases.

Advertisment