简体   繁体   中英

PHP force page to have header 200 status instead of 500 error

I have a php script that uses a third party API that requests information using OAuth and then outputs JSON and then I parse the JSON and foreach JSON tree response insert the data into a database, pretty simple, works great but sometimes the API handshake fails for various reasons and gives me a 500 internal error in the console.

The 500 error seems to be out of my control as it's accessing a third party. Is there a way to force the php script to give a status of 200 OK?

I have tried various combinations of the following and still cannot get it to stop the random 500 error in the console:

header("HTTP/1.1 200 OK");
error_reporting(0);
ini_set('display_errors', 'off');

Is there away?

Regardless I would assume what I am trying to do is bad practice but for this scenario, when the 500 error comes up it completely halts my script!

Server: Apache 2.4.16, PHP 5.5.28

What your server replies is entirely in your control. If you get a 500 error it's because your code isn't handling the failure, you probably have an exception being raised somewhere.

Check your error log and figure out where the issue is occurring, then handle the error condition and return what you would like.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM