After hours of searching and debugging I give up!
There are thousands of questions and articles about long running PHP processes but non of them solved my issue.
I have a PHP script with the following codes:
$cur = 0; // Second, loop for $timeout seconds checking if process is running while( $cur < 31 ) { sleep(1); $cur += 1; echo "\n ---- $cur ------ \n"; }
It is simply intended to run for 31 seconds.
I have a Nginx, PHP configured as fastcgi in debian server.
I set max_execution_time = 600
In
/etc/php5/fpm/php.ini
I even set it in
/etc/php5/cli/php.ini
Also set
request_terminate_timeout = 600
in /etc/php5/fpm/pool.d/www.conf
I also made these changes in nginx.conf http section
client_header_timeout 600; client_body_timeout 600; send_timeout 600; fastcgi_read_timeout 600; fastcgi_send_timeout 600; client_max_body_size 20m; fastcgi_buffers 8 128k; fastcgi_buffer_size 128k;
And put the directives inside server section. and these directives inside location section of nginx configuration
send_timeout 600; fastcgi_read_timeout 600; fastcgi_send_timeout 600; client_max_body_size 20m; fastcgi_buffers 8 128k; fastcgi_buffer_size 128k;
But I still encounter the Gateway Timeout error in the browser! (And Yes! I restarted php-fpm and nginx thousands of times)
Do you guys have any idea?
Here is my nginx.conf
# cat /etc/nginx/nginx.conf user www-data; worker_processes 4; pid /run/nginx.pid; events { worker_connections 768; # multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # SSL Settings ## ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE ssl_prefer_server_ciphers on; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; gzip_disable "msie6"; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_buffers 16 8k; gzip_http_version 1.1; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon; gzip_min_length 256; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; }
Here is /etc/nginx/conf.d/increase-timeout.conf
client_header_timeout 600; client_body_timeout 600; send_timeout 600; fastcgi_read_timeout 600; fastcgi_send_timeout 600; client_max_body_size 20m; fastcgi_buffers 8 128k; fastcgi_buffer_size 128k;
And this is my /etc/nginx/sites-enabled/mysite
server { listen IP:80;# default_server;## listen for ipv4; this line is default and implied #listen [::]:80 default ipv6only=on; ## listen for ipv6 root /path/to/root; index index.html index.php index.htm; server_name DOMAIN; access_log /var/log/nginx/mysite-access.log; error_log /var/log/nginx/mysite-error.log debug; client_header_timeout 600; client_body_timeout 600; send_timeout 600; fastcgi_read_timeout 600; fastcgi_send_timeout 600; client_max_body_size 20m; location / { if ($request_uri ~ ^/index.php.*$) { rewrite ^(.*)$ $1 last; } if ($request_filename = "index.html") { break; } if ($request_uri ~ .*php$) { set $test A; } if ($request_filename != "index.php" ) { set $test "${test}B"; } if ($test = "AB") { rewrite ^(.*)$ /index.html last; } } location ~ ^/index.php.*$ { fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; fastcgi_split_path_info ^(.+\.php)(/.+)$; set $path_info $fastcgi_path_info; fastcgi_param PATH_INFO $path_info; fastcgi_keep_conn on; # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; send_timeout 600; client_max_body_size 20m; fastcgi_read_timeout 600; fastcgi_send_timeout 600; fastcgi_buffer_size 128k; fastcgi_buffers 256 16k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; fastcgi_index index.php; include fastcgi_params; } }
if
statements andrewrite
statements look really odd here. For example,rewrite ^(.*)$ $1 last;
doesn't change the URI at all. What is the purpose of these statements in the first place?