我有一个很大的问题。 我有nginx和php5-fpm的站点安装它的一切工作很好,但大约一次(有时两次,或在所有的一天)php5-fpm崩溃。 我不知道为什么。 我尝试了很多次来改变一些configuration,但没有起到任何作用。 这一切工作正常,我什么也没有改变,但有一天,我看到网站上的网关错误..
服务器:2GB RAM,Intel(R)Celeron(R)CPU 2.66GHz,debian
这里是php5-fpmconfiguration:
[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错误日志:
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-fpmdebugging:
[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
最好的祝福
您达到活动孩子的最大数量。
检查你的:/var/log/php-fpm/slowlog.log缓慢的PHP脚本的一些提示,也尝试设置:
request_terminate_timeout = 50
最好的祝福
我相信你对pm.max_children的价值设定为45。
它应该在/etc/php-fom.d/*.conf中的某处
pm.max_children = 45
试着把这个价值提高到更重要的地步,因为你可以很清楚地看到你正在达到最高限度。
pm.max_children = 90
这应该解决这个问题。
此外,我不认为它是一旦达到最大限制,就会崩溃。 有什么地方是错的
你能告诉我你使用的是什么版本的php-fpm吗?