I am getting 504 timeouts message from nginx when my PHP script is running longer than usual. set_time_limit(0)
does not seem to prevent that! Does it not work when running php5-fpm on nginx? If so, whats the proper way of setting the time limit?
Error:
504 Gateway Time-out
nginx/1.2.7
Using
set_time_limit(0)
is useless when using php-fpm or similar process manager.Bottomline is not to use
set_time_limit
when usingphp-fpm
, to increase your execution timeout, check this tutorial.You need to add extra nginx directive (for
ngx_http_proxy_module
) innginx.conf
, e.g.:Basically the nginx
proxy_read_timeout
directive changes the proxy timeout, theFcgidIOTimeout
is for scripts that are quiet too long, andFcgidBusyTimeout
is for scripts that take too long to execute.Also if you're using FastCGI application, increase these options as well:
Then reload nginx and PHP5-FPM.
Plesk
In Plesk, you can add it in Web Server Settings under Additional nginx directives.
For FastCGI check in Web Server Settings under Additional directives for HTTP.
See: How to fix FastCGI timeout issues in Plesk?
The correct answer is increasing fastcgi_read_timeout in your Nginx configuration.
Simple as that!
There are several ways in which you can set the timeout for php-fpm. In
/etc/php5/fpm/pool.d/www.conf
I added this line:Also, in
/etc/nginx/sites-available/default
I added the following line to the location block of the server in question:The entire location block looks like this:
Now just restart php-fpm and nginx and there should be no more timeouts for requests taking less than 180 seconds.
Add these variables to nginx.conf file:
And then restart:
Since you're using php-fpm you should take advantage of fastcgi_finish_request() for processing requests you know can take longer.