Preventing nginx 504 gateway timeout with php set_time_limit ()

I get a message with 504 timeouts from nginx when my PHP script runs longer than usual. set_time_limit(0) does not seem to interfere with this! Does it work when running php5-fpm on nginx? If so, what is the correct way to set a time limit?

Mistake:

 504 Gateway Time-out nginx/1.2.7 
+68
php nginx fastcgi
Apr 14 '13 at 17:47
source share
9 answers

There are several ways to set a timeout for php-fpm. In /etc/php5/fpm/pool.d/www.conf I added this line:

 request_terminate_timeout = 180 

In addition, in /etc/nginx/sites-available/default I added the following line to the server location block:

 fastcgi_read_timeout 180; 

The entire location block is as follows:

 location ~ \.php$ { fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_read_timeout 180; include fastcgi_params; } 

Now just restart php-fpm and nginx, and there should be no more timeouts for requests that take less than 180 seconds.

+140
Jul 07 '13 at 10:48 on
source share

Try this link, it has the best solution to fix it. So the steps are:

  • Open the nginx.conf file located in the /etc/nginx directory.
  • Add this code snippet below in the http { section:

     client_header_timeout 3000; client_body_timeout 3000; fastcgi_read_timeout 3000; client_max_body_size 32m; fastcgi_buffers 8 128k; fastcgi_buffer_size 128k; 

    Note. If it is already present, change the values ​​to match.

  • Reboot Nginx and php5-fpm.

     $ service nginx reload $ service php5-fpm reload 

    If the error persists, consider increasing the values.

+23
Oct 10 '13 at 17:41
source share

You cannot use PHP to prevent a timeout issued by nginx.

To configure nginx to increase time, see the proxy_read_timeout directive.

+8
Apr 14 '13 at 17:51
source share

The correct answer increases fastcgi_read_timeout in your Nginx configuration.
Just!

+2
Oct 19 '16 at 2:37
source share

Since you are using php-fpm, you should use fastcgi_finish_request () to handle requests that, as you know, may take longer.

0
Apr 15 '13 at 16:20
source share

Using set_time_limit(0) useless when using php-fpm or a similar process manager.

The bottom line should not use set_time_limit when using php-fpm , to increase the execution timeout, check the tutorial .

0
Jun 27 '14 at 8:10
source share

You need to add an additional nginx directive (for ngx_http_proxy_module ) to nginx.conf , for example:

 proxy_read_timeout 300; 

Basically, the nginx proxy_read_timeout directive changes the timeout of the proxy server, FcgidBusyTimeout is for scripts that are too long, and FcgidBusyTimeout is for scripts that run too long.

Also, if you are using the FastCGI application, increase these parameters:

 FcgidBusyTimeout 300 FcgidIOTimeout 250 

Then reload nginx and PHP5-FPM.

Plesk

In Plesk, you can add it to your web server settings under Additional nginx Directives.

For FastCGI, check the web server settings in the Advanced HTTP Directives section.

See: How to fix FastCGI timeout errors in Plesk?

0
Apr 6 '16 at 23:27
source share
  sudo nano /etc/nginx/nginx.conf 

Add these variables to the nginx.conf file:

  proxy_connect_timeout 600; proxy_send_timeout 600; proxy_read_timeout 600; send_timeout 600; 

And then restart:

 service nginx reload 
0
Dec 23 '17 at 6:54 on
source share

I solve this problem with APACHE configuration! All methods (in this section) are wrong for me ... Then I try to configure chanche apache:

Timeout 3600

Then my script works!

-3
Sep 08 '16 at 14:44
source share



All Articles