2
votes

I've configured nginx with php-fpm on Ubuntu (and everything works pretty well).

One thing I encountered is that HTTP status code 200 is sent, when a PHP parse error occurs. The error log contains the following entry:

[error] 3205#0: *2854 FastCGI sent in stderr: "PHP Parse error: syntax error, unexpected T_REQUIRE_ONCE in /var/www/.../index.php on line 32" while reading response header from upstream, client: 1.2.3.4, server: example.com; request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "example.com"

I was not able to figure out, why not a code 50x is sent. I have not configured any error_page settings and I read the documentation of error_page. I also tried it to set the status code (with error_page 500 =500 /50x.html and so on). But always status 200 is returned.

I can send status headers from PHP (header('HTTP/1.1 404 Not Found')), this works. However, for errors issued by the PHP interpreter (also uncaught exceptions), the server's response doesn't take into account that an error occurred.

1
This is the way it responds on every webserver, you sure you want to do this? I mean there isn't really any use for it anyways, your script shouldn't fail and during development status 200 is fine if you can read the error.., if the status code isn't 200 newer browsers often use their own error page, so you can't read your error, which would make debugging more difficultAntwan van Houdt
Unfortunately, you're right. I just noticed that also mod_php sends status 200 on PHP errors (parse error, uncaught exceptions). That's really humble.. don't care about how to debug an error (as display_errors should be off in production), but I'm really astonished that PHP does this in a wrong way and outputs errors with "OK" status codes. No wonder that google is full of PHP error messages.StephenKing
Okay.. luckily it's not caused by PHP, but by xdebug: bugs.php.net/bug.php?id=50921StephenKing

1 Answers

2
votes

FYI, this is now fixed in Xdebug (2.2) for PHP 5.4 and up. Sadly, it needed a change in PHP to make it work that could not be back-ported to 5.3.