How can I get php to return 500 upon encountering a fatal exception?

后端 未结 10 1481
孤独总比滥情好
孤独总比滥情好 2020-12-24 10:37

PHP fatal errors come back as status code 200 to the HTTP client. How can I make it return a status code 500 (Internal server error)?

10条回答
  •  温柔的废话
    2020-12-24 11:00

    Since PHP >= 5.4

    http_response_code(500);
    echo json_encode( [ 'success' => false , 'message' => 'Crazy thing just happened!' ]);
    exit();
    

    Please set the httpCode before echo.

提交回复
热议问题