file_get_contents on IIS 6
Posted By Chris Stinson in Internet Information Server,PHP on May 18, 2007
To all those (3 people) who need to use file_get_contents in PHP on IIS 6, you may notice it doesn’t work by default. To see if it works, place the following code into a file called test.php.
You should have the first 20 bytes of the google source code echoed back to you on the page when it is executed. If not, you may need to play with IIS 6.
Does fsockopen work?
IIS 6 by default does not allow sockets to be created on port 80 (file_get_contents works on this port, of course). This is a result of how IIS 6 accepts connections. To get file_get_contents to work, you need to enable IIS 5 Compatibility (Isolation Mode) on IIS 6. You then need to choose Low (IIS Process) under “Application Protection.” Isolation mode settings are found in the IIS Admin Interface –> Right-click on Web Sites folder and look under the Service Tab.
Related posts:
- Unexpected Error 0x8ffe2740 when starting FTP or IIS
- WordPress 2.1.x – 2.2 Breaks PHP 4.4.4
- vBulletin / Photopost and MySQL 5
- How to install PHP ISAPI on Windows 2008 IIS7 x64
- How to Install PHP 5.3 FastCGI on Windows 2008 IIS 7


1 Comment
Just a word of warning: after trying this out, and then subsequently trying to switch IIS 5 compatibility mode off again, I somehow managed to render IIS completely unresponsive. I couldn’t start or stop any of the web sites, or the process itself, and eventually had to reinstall IIS on our development environment.
Make sure you have good backups before giving this a try!