If the server where your resource is located is overloaded (this happens due to the exhaustion of the traffic limit), it gives the user a message: "Error 504 gateway time out". Translated into Russian, this means: "The gateway's response time has elapsed, the gateway is not responding." A situation arises when Apache, purely physically, cannot process all http requests, and they queue up. However, the time limit passes, and a message appears stating that the request was not processed.
To remedy the situation, you need to optimize your server. To do this, you need to change the amount of RAM and the number of http (Apache) requests in the direction of their increase. Another option is to optimize the performance of all scripts on your site. This operation will help improve processing performance.
If you pay for your hosting, you should immediately contact support for help. The support service is obliged to check your site for any malfunctions and, if possible, “repair” it. Do not neglect such an opportunity. "Holes" that need to be patched may bemore than you think. Some hosting providers provide technical support by phone. This type of help is very useful if you are faced with technical problems such as error 504 for the first time. Thanks to this support, you can learn how to fix them yourself, without outside help.
There is another reason why a 504 error may occur: a script that executes some command does not fit into the time frame that is set for it. This may be due to a request for third-party resources, or he himself is doing something else at this time. For example, builds a search index.
To remove a bug, you can go in two ways:
1) lighten the script by optimizing it;
2) increase the value of the max_execution_time PHP parameter. Once again I would like to touch upon the technical support of the hosting provider where your site is located. Of course, everyone has his own, but the duties of supports are mandatory for everyone. There are times when questions sent to the support team go unanswered. Especially if it concerns any lags. For example, the same 504 error occurs. In this case, change hosting. If more serious problems begin, then you are unlikely to be able to count on their help.
There is one more point that should be mentioned. If your site is located on a free hosting and has a three-level domain, then do not expect your applications to be considered in the near future. FirstIn turn, such supports work with clients who monthly pay them for space on virtual disks. Of course, there is no reason to condemn them, because regular customers are more important. Therefore, if you want the 504 error to no longer bother you in the future, go straight to paid hosting. There is no catch in this, by switching to such a package, you will save yourself and your work on the Internet from many unwanted and unpredictable problems.
That's all I wanted to tell you about such a phenomenon as error 504. Let it occur to you as rarely as possible!