English 中文(简体)
PHP fopen/fwrite problem on IIS7
原标题:

I am running PHP5 on IIS7 on Windows Server 2008 R2. Check out the below code which writes a string received via a POST request parameter into an XML file.

<?php
$temp = "";
if($_SERVER[ REQUEST_METHOD ]=="POST"){
    if($_POST["operation"]=="saveLevels"){
        $fileHandle = fopen("c:\inetpub\wwwroot\test\xml\levels.xml",  w );
        fwrite($fileHandle, stripslashes($_POST["xmlString"]));
        fclose($fileHandle);
        $temp = "success";
    }elseif($_POST["operation"]=="saveRules"){
        $fileHandle = fopen("c:\inetpub\wwwroot\test\xml\rules.xml",  w );
        fwrite($fileHandle, stripslashes($_POST["xmlString"]));
        fclose($fileHandle);
        $temp = "success";
    }
}

When I make a POST request to invoke this code, the application pool owning/hosting the site containing php files, stops (due to some fatal errors, as it writes in event viewer) and then IIS keeps responding with HTTP503 after that. Now, I have given proper permissions to IUSR and IISUSRS on that (test/xml) directory. Those two XML files are not already existing, I have also tried the code when an XML file is already present but; it behaved the same way. What s wrong with that php code? I have tried it on a linux-box and it behaved as expected.

edit: I have tried various different versions of this code and came up with this result: the fopen call when awaken by a POST request, allways returns FALSE or sometimes NULL, and causes the Application Pool of itself to stop. The exact same code, works OK with a GET request, with exact same parameters. So; I dont know what the problem is but; for the time I m just going to use GET requests for this operation.

问题回答

Can you var_dump( $fileHandle) for both options, to show us what it has. I notice you re just assuming the file is opened, rather than checking the value (if it s FALSE the fwrite will fail)





相关问题
Session Management with Windows Authentication

In an ASP.NET web app, using Integrated Windows Authentication, is the session tied to the windows identity? In other words, if I login (using IWA) to the app, and the app stores some "stuff" in my ...

Using Elmah with Cassini

Does anyone know if I can use Elmah with Visual Studio build-in web server(aka Cassini)? I get it working easily on IIS, but using same configuration, it doesn t work with Cassini. When I requested ...

Setting hostname in IIS, include www?

I want to set the hostname for a website I m adding in IIS 7, however do I include the www in the hostname or not? because I want both www.mysite.com and mysite.com both to point to mysite on the ...

inetpub versus any other folder

I ve run websites out of inetpub, as well as from folders just residing on the C: drive. I wonder, are there any definitive advantages to running websites out of inetputwwwroot?

IIS 6.0 hangs when serving a web-service

I am having issues with one of our web-services. It works fine on my development machine (win XP) whether I host it as a separate application or using cassini from Visual studio. Once I deploy on the ...

热门标签