Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to know if an error 504 Gateway timeout always come from the load balancer or it can also be originated from Apache and the PHP code it's running ?


share|improve this question

It usually happens when the load balancer is waiting for a response from apache and apache is not giving a response within the timeout period of load balancer. So it returns a 504 gateway timeout. About what causes apache to not respond is something only you can say as you have not given much background information on what apache is serving. Look at apache logs to know more details . usually access logs and error logs. Increase the timeout value of loadbalancer, to see if it helps. It is always good to have clustering on apache so you dont get 504 because of a dead apache instance. I think mod_proxy allows you to achieve software clustering. I am not sure check out on apache site.

share|improve this answer

Usually from balancing because Apache(mod_php) or PHP(FastCGI) down or busy.

share|improve this answer

Sure it can be from php. If php script is in some loop and wont 'spit' out the content connection will eventually time out and balancer will report gateway timeout.

That 'loop' does not necessarily need to be loop, it can be waiting on connection to some service to read data from like mysql/memcache or something...

share|improve this answer
You're wrong. PHP it's not web-server and can't send any HTTP response. – ooshro Feb 24 '11 at 14:54
Not entirely true, @ooshro, PHP can set headers with header().. but I'm not entirely sure that's appropriate in this instance. – Tom O'Connor Feb 24 '11 at 15:00
@Tom You're wrong. PHP need use socket to send any network message. header() need mod_php, CGI or FastCGI. – ooshro Feb 24 '11 at 15:05
The OP says " from Apache and the PHP code it's running" Assuming some kind of mechanism between apache and PHP. One that is capable of handling header() – Tom O'Connor Feb 24 '11 at 15:10

Your Answer


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.