M
M
Maxim2013-07-29 15:36:34
PHP
Maxim, 2013-07-29 15:36:34

How to get an error code other than 200 from PHP-FPM on PHP Fatal error?

Given: Nginx 1.4.1, PHP-FPM 5.3.27
When a fatal error occurs in PHP, the web server returns the error text and code 200.
Okay, we register in nginx according to the advice of the best dog breeders:
fastcgi_catch_stderr "PHP Fatal error:";
Fatal error now returns 502 Bad Gateway, but this time there is no error text.
It is necessary: ​​to return an erroneous code and display the error itself in the browser, as Apache does. If, in addition, it will be possible to change the 502 code to something more sane, it will be very good.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
A
Aleksandr Kuznetsov, 2013-07-30
@x_T

Isn't this bug caught?

K
kenny_opennix, 2013-07-29
@kenny_opennix

It's not entirely clear what you want, if your error page is nginx.org/ru/docs/http/ngx_http_core_module.html#error_page
Or are you asking about fastcgi_intercept_errors?
If about this option, then it is enough to specify fastcgi_intercept_errors on;

K
kenny_opennix, 2013-07-30
@kenny_opennix

What you want is usually done on the side of the frameworks. let's say this behavior yii represents, on the nginx side, error pages are disabled and yii generates an error page.

R
russianlagman, 2013-07-30
@russianlagman

Write a handler for a fatal error that will return both the text and the correct error code: www.php.net/set-error-handler
The handler is connected to any file with the auto_prepend_file directive.

K
kenny_opennix, 2013-07-30
@kenny_opennix

php_flag[display_errors] = on
included in fpm?
I have a bunch of nginx + php-fpm and errors like
Parse error: syntax error, unexpected T_STRING in are displayed
.

A
Arks, 2013-07-30
@Arks

This error should be resolved on the nginx side. In the default behavior, everything is fair - the backend gave it the text (html) - it honestly returned the response 200.
As, I also guess, unfortunately ((
However, the custom error handler in php is a crutch, but it’s quite a solution for php-fpm.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question