Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a php website that will be experiencing high levels of traffic in a few weeks. We scaled the servers to accept the traffic, but want some sort of fallback page in the event that something happens.

Does anyone know of an easy way to implement this?

My initial thought is to check for the headers when the page is requested, but don't quite understand if that will even matter. Does the user even receive the initial http headers, if they get a 504 Gateway Timeout error?

Would something like checking the result of: var_dump(http_response_code()); in a conditional even reach the client?

share|improve this question
    
This is a problem for your webserver, not for PHP. If you are using Apache, start here: httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html –  Yannis Rizos Oct 4 '13 at 14:38
    
As @YannisRizos says - I would say this question could find a good home on ServerFault. –  glenatron Oct 4 '13 at 14:44
    
Zend Server offers clustering and rules of what to do when the cluster is overloaded. zend.com/en/products/server/multi-server-support there is no simple PHP hack to solve demand problems. –  Mathew Foscarini Oct 4 '13 at 15:18
    
Thank you all for the resources... I will check them out. We're using apache so I might check that out first @Yannis Rizos. –  Seth Oct 4 '13 at 18:10
    
Is this something you could make static? Blog posts and so on often get a lot of traffic, but could trivially be turned into a static resource. A much smaller server running something like nginx will serve static content long after a larger box running a dynamic site has collapsed. Downside is, of course, you can't be dynamic any more, so it's not applicable there. –  Phoshi Oct 8 '13 at 10:55

1 Answer 1

up vote 2 down vote accepted

For a better answer we certainly could use some more information, for example:

  • What web server are you using?
  • How are you balancing connections to them?
  • Do you have any layer of cache?
  • What kind of data do you send clients? Can it be cached? It is behind an HTTPs-only protocol?

Based on the information you gave, I would discourage doing what you want to do in PHP. As you may have guessed, depending on the occasion (all workers are busy processing other requests), PHP won't even be triggered and a 504 header will be sent to the client as a response by the web server, without reaching PHP as you already expect.

I would recommend a HTTP cache layer before all requests, like Varnish. By default it will cache pages and prevent that your web servers get overloaded. In the event of that happening, you can easily configure varnish to send a response (HTML page, for example) instead of the 504 page. But if the page can be cached, than if you have more than one varnish load balanced with HAproxy (for example) you will hardly experience the problem.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.