0

My script sometimes takes more than 2 minutes and I am getting "504 Gateway Timeout Error" sometimes.

Following are the php server settings

max_execution_time 6000 (Local), 120 (Master)
max_input_time 120
memory_limit -1

I also tried using set_time_limit(0) but getting same error.

I also tried creating a php.ini at root directory with max_input_time=-1 but it is not updating

When I check in console Network section, the script timeouts after 1.1 minutes giving 504 gateway timeout error.

I checked the phpinfo(), Server type is fastCGI. On my local system (wamp) the script runs perfect. On local Server type is apache mod_php. It can be issue?

Please guide me how I can solve this issue.

Any help will be appreciated.

alessandrio
  • 4,282
  • 2
  • 29
  • 40
Sunny
  • 1
  • 1
  • 1
  • Welcome to StackOverflow, Sunny. Have you checked the server error log? Without any code and narrowing down the location where the script begins to exceed the timeout, we cannot be of much help. Please attempt to Edit your question (using the edit link between share and flag) a provide us more specific info. – David May 21 '17 at 22:33
  • Hi David, Thanks for your quick response.. I am not getting any other error. The gateway timeout error appears on the page when the request takes more than 2 minutes. – Sunny May 22 '17 at 12:06
  • Having done testing on local system and live on production server before, two things come to mind. One are the php versions the same & do you have 'editing' rights to the php process. Running on shared servers, I often found company imposed limitations. That being said, it sure sounds like something in your script is hanging. Try adding some `print` or `fwrite` statements to find the guilty line of code. – David May 22 '17 at 16:01
  • Can you please share more about how to use print and fwrite in the script to try fix? The request is fetching records from multiple tables and then there are conditions and loops to process the results and then finally display the html output. – Sunny May 22 '17 at 21:55
  • Does the problem server have remote mysql access? A 504 error might also be a problem in .htaccess. – David May 22 '17 at 23:25
  • `print('line: '.__LINE__);` spaced a special points may help you see where the script becomes unresponsive. However, the server may not send output to the screen (another issue and question). `fwrite($fp, "__LINE__\n");` would be written to a file after `$fp = fopen('output_file.txt', 'w');` This can be tricky to get working also. See the php.net manual for both. Your problem and question is very open and hard for us to troubleshoot. These two tricks may help you narrow down the cause of the problems. – David May 22 '17 at 23:32
  • David, sorry for late reply.. yes there is htacess.. htaccess has password require restriction for directory when user try to access that directory using the path in url... what can be issue in htaccess? And there is one more htaccess at the root of the website which contains mod rewrite enable, some redirects. – Sunny May 25 '17 at 05:54
  • And I will check if I find anything using print. – Sunny May 25 '17 at 06:01
  • Possible duplicate of [Prevent nginx 504 Gateway timeout using PHP set\_time\_limit()](https://stackoverflow.com/questions/16002268/prevent-nginx-504-gateway-timeout-using-php-set-time-limit) – Stephan Weinhold Jun 16 '17 at 11:11

0 Answers0