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?

  • 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 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. – Reactgular 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

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.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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