5

I would like to increase timeout of one php site on nginx so I don't get "504 Gateway timeout". I've tried set_time_limit but it doesn't work. I've found some solutions which are based on modification of configuration files (e.g. Prevent nginx 504 Gateway timeout using PHP set_time_limit()). However I shouldn't modify these files in my case. Is there such a way?

Thanks for any efforts.

3
  • did you figure this out? Commented Sep 18, 2015 at 6:35
  • @timh: No, I haven't. Commented Sep 22, 2015 at 16:29
  • why to do set_time_limit on client facing scripts? It's not right approach. Think about alternative solutions. I use set_time_limit only in backend workers where I'm handling queues and etc. Commented Aug 3, 2016 at 21:53

1 Answer 1

3

First, you have to edit your Nginx configuration files to change fastcgi_read_timeout. There is no getting around that, you have to change that setting.

I'm not sure why you say "I shouldn't modify these files in my case". I think your reason might be that you want to change the timeout for one of your websites, but not others. The best way I've found to accomplish that is go ahead and set fastcgi_read_timeout to a very long timeout (the longest you would want for any of your sites).

But you won't really be counting on using that timeout, instead let PHP handle the timeouts. Edit your PHP's php.ini and set max_execution_time to a reasonable amount of time that you want to use for most your websites (maybe 30 seconds?).

Now, to use a longer timeout for a particular website or web page, use the set_time_limit() function in PHP at the beginning of any scripts you want to allow to run longer. That's really the only easy way to have a different setting for some websites but not others on a Nginx / PHP-FPM set up. Other ways of changing the timeout are difficult to configure because of the way PHP-FPM shares pools of PHP threads with multiple websites on the server.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.