IIS 7 / 7.5, FastCGI hosting PHP and Compression

by Vivek 12/7/2009 12:51:00 AM

We know how to enable HTTP Compression in IIS 7/7.5. We also have articles on enable compression for .aspx or .asp or a static HTML files. Here we will see how to enable compression on FastCGI hosted PHP website in IIS 7/7.5.

I have a default installation of IIS 7.5 and installed PHP 5.3.1 from PHP For Windows. I also followed the article Using FastCGI to Host PHP Applications on IIS 7.0 to configure FastCGI and PHP. I am using Fiddler Web Debugger to check if compression is working.

Now, let’s check compression:

  1. Open Internet Explorer and open Fiddler by clicking Tools –> Fiddler2
  2. type the URL http://<machinename>/phpinfo.php
  3. The PHP version information page is displayed
  4. Let’s check Fiddler if the .php is getting compressed
    image1
  5. Now, let’s install Dynamic Content Compression from Roles –> Web Server (IIS) –> Add Role Services
  6. Once, you have Dynamic Content Compression installed
  7. Go to IIS Manager, and double click Compression and verify if “Enable dynamic content compression'” is selected.
  8. Repeat the steps 1 to 3 again
  9. This time Fiddler shows
    image2
  10. You will need Dynamic Content Compression installed and enabled to get FastCGI PHP pages to be compressed.

NOTE:

In IIS 6.0, an .aspx page with .css file and Dynamic Compression disabled will compress .css file if you have Static Compression enabled. In IIS 7/7.5, .aspx page with .css file will not compress .css file though we have Static Compression enabled. To compress .css files from the very first request, you will need to enable Dynamic Content Compression in IIS 7/7.5.

Refer the article Changes to compression in IIS7 for better understanding of the behaviour.
<snip>

In IIS6, static compression was happening on a separate thread. So on receiving a request, first response was uncompressed and IIS used to start a separate thread to compress the file and keep it in compressed files cache. Requests for compressed content reaching IIS after the compression is complete used to receive compressed response. In IIS7, compression happens on the main thread. But to not incur cost of compression for all requests compression happens only for frequently requested content. Definition of frequently requested content is controlled by properties frequentHitThreshold and frequentHitTimePeriod under section system.webServer/serverRuntime. If IIS receives more than threshhold number of requests in frequentlyHitTimePeriod for the same url, IIS will go ahead and compress the file to serve compressed response for the same request which made IIS reach threshhold.

</snip>

Hope this helps,
Vivek Kumbhar


Quote of the day:
Cocaine is God's way of saying that you're making too much money. - Robin Williams

Tags: , , , ,

FastCGI | HTTPCompression | IIS 7

blog comments powered by Disqus

Who is Rahul?

Rahul

He works for Microsoft and likes Software & Gadgets!

He shares some interesting notes here while working with stuff that excites him.

Disclaimer

The opinions expressed herein are our own personal opinions and do not represent our employer's view in any way.
© Copyright 2014, Rahul Soni