Reputation: 709
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.
Upvotes: 4
Views: 3250
Reputation: 9927
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.
Upvotes: 2