6
正如許多其他問題所指出的,在php.ini中將display_errors設置爲Off將使Web服務器在遇到致命錯誤時回答狀態碼爲500內部服務器錯誤,而不是200 OK。我設置了一個未定義功能簡單的測試來解釋行爲:爲什麼display_errors會更改HTTP狀態碼?
的php.ini
display_errors = On
的index.php
<?php test();
給出:
Fatal error: Call to undefined function test()
in D:\xampp\htdocs\index.php on line 1
或只是一個空白頁面,如果我沉默這樣的函數調用:
<?php @test();
在這兩種情況下,回答標題如下:
HTTP/1.1 200 OK
Date: Tue, 10 Jul 2012 20:08:22 GMT
Server: Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By: PHP/5.3.8
Content-Length: 0
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
雖然改變的php.ini:
display_errors = Off
原因:
HTTP/1.0 500 Internal Server Error
Date: Tue, 10 Jul 2012 20:10:35 GMT
Server: Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By: PHP/5.3.8
Content-Length: 0
Connection: close
Content-Type: text/html
可有人給我解釋一下墊層當display_errors關閉時,使Web服務器回覆500的機制?
Interresting,我想知道,只要有致命的錯誤,它應該總是返回500。我也想知道爲什麼... – 2012-07-10 20:18:10
重複:http://stackoverflow.com/questions/3570747/display-500-error-on-any-error-in-apache – 2012-07-10 20:23:27
這似乎是一個不同的問題 – 2012-07-10 20:33:31