Prevent nginx 504 Gateway timeout using PHP set_ti

2019-01-08 04:24发布

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

9条回答
2楼-- · 2019-01-08 05:20

You can't use PHP to prevent a timeout issued by nginx.

To configure nginx to allow more time see the proxy_read_timeout directive.

查看更多
老娘就宠你
3楼-- · 2019-01-08 05:22

Try this link, it has a better solution on how to fix this. So the steps are:

  1. Open your nginx.conf file located in /etc/nginx directory.
  2. Add this below piece of code under 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 its already present , change the values according.

  3. Reload Nginx and php5-fpm.

    $ service nginx reload
    $ service php5-fpm reload
    

    If the error persists, consider increasing the values.

查看更多
何必那么认真
4楼-- · 2019-01-08 05:23

I solve this trouble with config APACHE ! All methods (in this topic) is incorrect for me... Then I try chanche apache config:

Timeout 3600

Then my script worked!

查看更多
登录 后发表回答