how to trigger a 503 on error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mybikeisgreen
Forum Newbie
Posts: 22
Joined: Thu Oct 01, 2009 6:22 pm

how to trigger a 503 on error

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: how to trigger a 503 on error

Post by requinix »

mybikeisgreen
Forum Newbie
Posts: 22
Joined: Thu Oct 01, 2009 6:22 pm

Re: how to trigger a 503 on error

Post 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.
mybikeisgreen
Forum Newbie
Posts: 22
Joined: Thu Oct 01, 2009 6:22 pm

Re: how to trigger a 503 on error

Post 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()
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: how to trigger a 503 on error

Post 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.
mybikeisgreen
Forum Newbie
Posts: 22
Joined: Thu Oct 01, 2009 6:22 pm

Re: how to trigger a 503 on error

Post by mybikeisgreen »

This answer was not very helpful. Why not elaborate or provide code examples? :banghead: Thanks.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: how to trigger a 503 on error

Post by jackpf »

trigger_error() and set_error_handler().
Post Reply