header("HTTP/1.1 503 Service Unavailable");

I am trying to generate a 503 error, I have put in:
header("HTTP/1.0 503 Service Unavailable");
header("HTTP/1.1 503 Service Unavailable");
header("Status: 503 Service Unavailable");

But still the page is giving 200 OK.
I'm using PHP 4.4 + Apache 2.0
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


Firstly, I am not sure you can force a 503 error, since this is the Service Unavailable error.  I'm not saying 100% that it cant be done, because I do it all the time for 40X errors.

Basically, I think the "200 OK" is coming from the web server, which is reporting that it was successful in delivering the page, whatever you have put in the header statement.

You could try making sure that no whitespace is in the document, as this will force the server to write the headers before you get to output your 503.

Also try just constructing the entire HTML of a 503 page, and use that instead.  This will get around PHP automatically adding in your <html><head>...</head><body></body> section when you have not defined it.  Again, this will over-ride your 503 so you need to avoid it.

Finally, the normal way to issue a 503 (because your site is down for maintenance for example), is to use a mod_rewrite rule in an htaccess file:

   RewriteEngine on
   RewriteRule !offline.php$ http://www.mydomain.com/offline.php [R,L]

Then your offline.php script would be something like:

   header("HTTP/1.1 503 Service Unavailable");
   echo "The site is currently offline";
Hope this is a help.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.