I want to pass PHP error as Internal Server Error to IIS

Asked 5 months ago, Updated 5 months ago, 23 views

I am currently creating an application for PHP
It's almost finished and I'm making adjustments for the release.
Would it be possible to pass over the script error that occurred in PHP as an IIS Internal Server Error?



Then, on the screen,

Parse error:syntax error, unexpected 'try' (T_TRY) in C:\inetpub\wwwroot\AAAA\BBBB.php on line 3

appears (it may be too extreme for example)

This is not a PHP error like this
I would like to display a general error screen displayed in IIS

PHP logs are

[25-Aug-2015 11:51:25 Asia/Tokyo] PHP Parse error:syntax error, unexpected 'try' (T_TRY) in C:\inetpub\wwwroot\AAAA\BBBB.php online3

IIS logs are

2015-08-2502:48:43 POST/AAAA/BBBB.php-- Mozilla/5.0+ (Windows+NT+6.1; +WOW64; +rv:40.0) + Gecko/20100101 + Firefox/40.0 http://localhost/AAA/2000343

Therefore, IIS seems to have finished normally

If possible, I would like to notify IIS as an error, but where should I mess with php.ini settings?

php iis

2022-09-30 14:03

3 Answers

If you want to replace HTTP 200 with HTTP 500, display_errors is Off or 0.

If display_errors=On or display_errors=1, the PHP engine also outputs on E_PARSE or E_ERROR.

If you want to see PHP errors in IIS logs, use error_log.For example: php.ini

 error_log = syslog
log_errors_max_len = 0; 'Infinite'

The error passes to the system logger (same destination as syslog):

Enter a description of the image here

Note, if you do not configure error_log, the log will automatically go to IIS:

If this directive is not configured, the error is sent to the SAPI error logger.This is, for example, Apache error logs, or stderr for the CLI.

It says so, but somehow it has to be ruined.(The error message does not appear in IIS logs and is visible in the browser.web.config Something went wrong (English link)

error_logIf you do not want to set it, you can set it directly.First locate the site log:

Enter a description of the image here

Configure php.ini.Example:


(Note, one server may have multiple sites.Each site has its own log.)

Reboot with iisreset or:

net stop w3svc
net start w3svc

Allow write and load at the end, give to selected users:

Enter a description of the image here

Most of the users are IIS_IUSRS (IUSR I've heard opinions claiming that, but I can't achieve the results.But that may be the case.) Authentication is an authenticated user (English link).

2022-09-30 14:03

I don't know how to deal with Syntax errors, but the combination of PHP-provided features allows for some error handling.
The element is
I will use something like that.
In other words, you should use error_get_last() to find out why you stopped when the script ended and set the error status in header() if it is not successful.At that time, header() has a restriction that data should not have been sent before that time, so it first buffers with ob_start() and puts the message on hold.
It's going to be a very large organization, so I can't just put it in the final adjustment.I used to stock this in the class that sends data at JSON.It's mainly because it's troublesome to look at the error log to debug.

2022-09-30 14:03

Internal Server Error is HTTP Code 500 Series, so
I think I should return 500 series responses among PHPs.

header('HTTP/1.1500 Internal Server Error');

2022-09-30 14:03

If you have any answers or tips

© 2023 OneMinuteCode. All rights reserved.