Page 1 of 1

how to trigger a 503 on error

Posted: Thu Oct 01, 2009 6:26 pm
by mybikeisgreen
I'm working on a php page that accepts automated requests. The automated requests look for a response code from the page. When it see 200 OK it infers the light is green, and everything worked as it should have. So I'd like for it to give a 503 response code if there is any kind of error, such as an include file missing or a mysql error. Is there a setting in PHP that I can set to make it do that? I only want to do it for this one page, not the whole site/server.

Re: how to trigger a 503 on error

Posted: Thu Oct 01, 2009 6:43 pm
by requinix

Re: how to trigger a 503 on error

Posted: Thu Oct 01, 2009 6:48 pm
by mybikeisgreen
Thanks but that page tells you how to manually create a 503 response header. I want it to happen automatically and only in case of an error.

Re: how to trigger a 503 on error

Posted: Thu Oct 01, 2009 11:24 pm
by mybikeisgreen
Still looking for an answer here. I was hoping that there was something I could do with the error_reporting() function to make this work.

But it's starting to look like I'll need to use try{} catch()

Re: how to trigger a 503 on error

Posted: Fri Oct 02, 2009 12:22 am
by requinix
You can set an error and an exception handler (guess what the function names are) to automatically send that header() if there's a problem.

As for a setting to PHP to do it for you, I don't know of any such thing.

Re: how to trigger a 503 on error

Posted: Fri Oct 02, 2009 4:21 am
by mybikeisgreen
This answer was not very helpful. Why not elaborate or provide code examples? :banghead: Thanks.

Re: how to trigger a 503 on error

Posted: Fri Oct 02, 2009 5:01 am
by jackpf
trigger_error() and set_error_handler().