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:
- Open Internet Explorer and open Fiddler by clicking Tools –> Fiddler2
- type the URL http://<machinename>/phpinfo.php
- The PHP version information page is displayed
- Let’s check Fiddler if the .php is getting compressed
- Now, let’s install Dynamic Content Compression from Roles –> Web Server (IIS) –> Add Role Services
- Once, you have Dynamic Content Compression installed
- Go to IIS Manager, and double click Compression and verify if “Enable dynamic content compression'” is selected.
- Repeat the steps 1 to 3 again
- This time Fiddler shows
- You will need Dynamic Content Compression installed and enabled to get FastCGI PHP pages to be compressed.
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.
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.
Hope this helps, Quote of the day:
Cocaine is God's way of saying that you're making too much money. - Robin Williams