Linux – nginx, php5-fpm crashing

linuxnginxphp-fpm

I have a big problem. I have site with nginx and php5-fpm installed it all works great but about one time(sometimes two times, or at all) in a day php5-fpm crashing. I don't know why.
I tried many times to change some config but it doesnt gave any effect.
It was all working ok, I don't changed anything, but one day i see gateway error on my site..

Server: 2GB ram, Intel(R) Celeron(R) CPU 2.66GHz, debian

Here is php5-fpm config:

[www]
#listen = 127.0.0.1:9000
listen.backlog = 128

listen = /var/run/php-fpm/php-fpm.sock
;listen.backlog = -1
;listen.allowed_clients = 127.0.0.1
listen.owner = www-data
listen.group = www-data
;listen.mode = 0666
user = www-data
group = www-data
pm                   = dynamic
pm.max_requests      = 400
pm.max_children      = 45
pm.start_servers     = 7
pm.min_spare_servers = 2
pm.max_spare_servers = 9

request_terminate_timeout = 0

request_slowlog_timeout = 45s
slowlog = /var/log/php-fpm/slowlog.log

catch_workers_output = yes

php_admin_value[display_errors] = 'stderr'
php_flag[display_errors] = On
php_admin_value[memory_limit] = 50M
php_admin_flag[display_startup_errors] = on
rlimit_files = 1024
rlimit_core = 0

php_admin_flag[log_errors] = on
php_admin_value[error_log]  = /var/log/php-fpm/pool.log
php_admin_value[error_reporting] = 'E_ALL & ~E_DEPRECATED'
php_admin_value[display_errors] = off
php_admin_flag[display_startup_errors] = on

Nginx cfg:

    upstream php_fpm {
        server unix:/var/run/php-fpm/php-fpm.sock;
    #server 127.0.0.1:9000;
    }

    server {
        listen   80;
        server_name  here is my domain;
        access_log  /var/log/nginx/site.access.log;
        error_log /var/log/nginx/site.error.log;

        root   /home/www/site/public;

        index index.php;


    location /status {
        stub_status on;
        access_log   off;
        allow 127.0.0.1;
    deny all;
        }
        error_page 500 = index.php;

    fastcgi_intercept_errors on;
        #try_files $uri @php_index; 

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires 1d;
    log_not_found off;
    }
      location / {
        #index index.php;
        try_files $uri $uri/ /index.php;
      }

      # Deny access to sensitive files.
      location ~ (\.inc\.php|\.tpl|\.sql|\.tpl\.php|\.db)$ {
        #deny all;
        #try_files $uri $uri/ /index.php = 404;
        deny all;
      }
      location ~ \.htaccess {
        deny all;
      }

      # Rewrite rule adapted from zendapp/public/.htaccess
      if (!-e $request_filename) {
        rewrite ^.*$ /index.php last;
      }

      # PHP scripts will be forwarded to fastcgi processess.
      # Remember that the `fastcgi_pass` directive must specify the same
      # port on which `spawn-fcgi` runs.
      location ~ \.php$ {

    try_files $uri = 404;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_pass   php_fpm;
        fastcgi_index  index.php;


fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;



        fastcgi_ignore_client_abort     off;
        fastcgi_connect_timeout 60;
        fastcgi_send_timeout 180;
        fastcgi_read_timeout 180;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;


#fastcgi_send_timeout 150s;
#fastcgi_read_timeout 150s;

 #      fastcgi_buffer_size 128k;
  #      fastcgi_buffers 4 256k;
   #     fastcgi_busy_buffers_size 256k;
    #    fastcgi_temp_file_write_size 256k;
    include fastcgi_params;


    }



}

Nginx error log:

2012/12/20 04:47:01 [error] 16995#0: *158917 upstream timed out (110: Connection timed out) while reading response header from upstream, client: server_ip, server: domain, request: "GET / HTTP/1.0", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "domain"
2012/12/20 04:51:01 [error] 16995#0: *158952 upstream timed out (110: Connection timed out) while reading response header from upstream, client: server_ip, server: domain, request: "GET / HTTP/1.0", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "domain"
2012/12/20 04:53:01 [error] 16995#0: *158977 upstream timed out (110: Connection timed out) while reading response header from upstream, client: server_ip, server: domain, request: "GET / HTTP/1.0", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "domain"
2012/12/20 04:55:01 [error] 16995#0: *158998 upstream timed out (110: Connection timed out) while reading response header from upstream, client: server_ip, server: domain, request: "GET / HTTP/1.0", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "domain"
2012/12/20 04:58:31 [error] 16995#0: *159064 connect() to unix:/var/run/php-fpm/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 66.249.74.xx, server: domain, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "domain"
2012/12/20 04:58:38 [error] 16995#0: *159066 connect() to unix:/var/run/php-fpm/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 173.199.120.xx, server: domain, request: "GET /d HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "domain"
2012/12/20 04:58:42 [error] 16995#0: *159068 connect() to unix:/var/run/php-fpm/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 66.249.74.xx, server: domain, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "domain"
2012/12/20 04:58:52 [error] 16995#0: *159070 connect() to unix:/var/run/php-fpm/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 180.76.5.xx, server: domain, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "domain"
2012/12/20 04:58:53 [error] 16995#0: *159072 connect() to unix:/var/run/php-fpm/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 66.249.74.xx, server: domain, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "domain"
2012/12/20 04:58:53 [error] 16995#0: *159074 connect() to unix:/var/run/php-fpm/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 66.249.74.xx, server: domain, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "domain"

PHP5-fpm debug:

[20-gru-2012 04:58:46.960245] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:47.961359] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:48.962426] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:49.963480] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:50.964540] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:51.965601] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:52.966705] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:53.967821] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:54.968938] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:55.970062] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:56.971134] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:57.972193] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1

Best Regards

Best Answer

You reach the maximum number for active childs.

Check your: /var/log/php-fpm/slowlog.log for some hint on slow php scripts and also try to set:

request_terminate_timeout = 50

Best regards

Related Topic