简体   繁体   中英

PHP + IIS : file_get_contents “hangs” using a localhost URL

Small context : I develop an eval function that is capable to detect parsing issues. It needs file_get_contents on a created PHP file using its URL. Please don't say EVAL is EVIL. I'll post my new eval function after fixing this issue

OK. Simple test :

$fc = "Not executed";
$tmpDir = "var/temp-eval/";
$tmpfname = "t.php";
$ctx = stream_context_create(array( 
    'http' => array( 
        'timeout' => 1 
        ) 
    ) 
); 

echo "BEGIN<br>";

//// Both below makes the page hangs
// TRY #1
//$fc = @file_get_contents(Common::getRootUrl() . $tmpDir . $tmpfname, false, $ctx);
// TRY #2
//$fc = @file_get_contents(Common::getRootUrl() . $tmpDir . $tmpfname);

//// Below, doesn't hang
// TRY #3
//$fc = file_get_contents("http://www.SOMEWEBSITE.COM");
echo $fc;

echo "<br>END";

Keeping as is, all commented, it works. The page finishes loading and shows the HTML.

Uncommenting either TRY #1 or TRY #2 (internal URL), the page never finishes to load. But... using xdebug and following the code, I can see the content gotten in $fc and the code seems to work fine - except the hang -. But... using this code on a Linux server using Apache, it works perfectly. :) :(

Uncommenting TRY #3 (external URL), it works fine on both environment.

I suspect a configuration in IIS that has some difficulties to run two webpages currently, but did not find anything searching the web.

SETUP : IIS 10 + Windows 10 Home + PHP 5.6

Finally, before posting my answer, I continued the search and found people talking about running FastCGI instead of CGI. So it works. I post it here in case of other people encounters the same issue without knowing what to search to fix the issue.

FastCGI is native with IIS 10, I don't know the other versions, but it is installable (though probably all versions in use have it natively).

So I added a Module Mapping from "Application Extension Mapping" (I have it french, so I took the name from the old version page I had) by choosing : Module=FastCGI, Executable=PATH-OF-PHP/php-cgi.exe.

Page from Microsoft stating how to install it on IIS 6.0: https://www.iis.net/learn/application-frameworks/install-and-configure-php-applications-on-iis/using-fastcgi-to-host-php-applications-on-iis-60

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM