开发者

Empty variable in PHP script causes IIS7 to throw an HTTP 500 error

开发者 https://www.devze.com 2022-12-08 22:52 出处:网络
I am running IIS7 and PHP5 locally开发者_Python百科 on my machine and the code above will cause IIS to throw an HTTP 500 error. After a lot of frustration and confusion I figured out that any PHP scri

I am running IIS7 and PHP5 locally开发者_Python百科 on my machine and the code above will cause IIS to throw an HTTP 500 error. After a lot of frustration and confusion I figured out that any PHP script with empty variable will throw this IIS error. Below is an example of this:

<?php $x = $y; ?>

I find this behavior very odd and it breaks a large percentage of the code I write. In most cases it prevents me from debugging properly. I would really really like to see output and error messages. Also, this can break the usage of the super globals GET and POST and can only be suppressed by logic to prevent their execution.


PHP is throwing an exception, printing to stdout, and reporting the error properly in all likelihood. IIS is probably ignoring that and throwing the 500.

Try logging your errors to file instead of displaying them, which may appease IIS. I believe it's:

display_errors = Off
log_errors = On
error_log = "C:/YourWWW/errors.txt"

...but I don't have a php.ini handy to check.

Back to the issue, if $y is empty, what do you expect PHP to do? Any sane programming language will vomit when you try to assign a non-existent variable. This will sound harsh, but if that "breaks the majority of code you write", you're doing something wrong. Also, not sure what you mean by "break the usage of" $_GET and $_POST. If you mean this will throw a 500:

$foo = $_GET["nonexistentvar"];

...then you're quite right it will. You should be checking for the existence of the key before expecting PHP to assign something that doesn't exist. Pow, no 500:

$foo = isset($_GET["nonexistentvar"]) ? $_GET["nonexistentvar"] : NULL;

Sorry if I sound hostile, but you came across really whiny in your question.


I use IIS7 + PHP setup using the fascgi module and do not get this issue. PHP outputs errors properly. I would verify that you have PHP and IIS set up properly according to this guide:

http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis-70/

The most common pitfall is that you assigned IIS to call php-win.exe or php.exe vs calling php-cgi.exe. Also, some of the php.ini settings can cause this problem. I cannot recall which however.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号