Posted by & filed under Internet Information Server, PHP.

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.

<?php
$content=file_get_contents("http://www.google.com",FALSE,NULL,0,20);
echo $content;
?>

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.

(No Ratings Yet)

One Response to “file_get_contents on IIS 6”

  1. Jacob Hume

    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!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>