Php5-fpm如果有很多访客则会崩溃

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Php5-fpm如果有很多访客则会崩溃脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我决定将我的OP从LITesPEed改为Nginx因为我读了很多关于Nginx会花费的资.

我在线运行一个有500个用户WordPress网站

好的,谢谢大家的帮助:)我编辑了一些东西.

我也有一些问题:

我必须删除;在下午之前.设置?我删除了什么配置?我在/etc/PHP5/FPM中有两个快速的cgi,一个名为PHP-fpm.conf,一个在/etc/PHP5/fpm/pool.d中,名为www.conf?

我在晚上尝试了新的配置,当我醒来时,我已经有了一个空白页面.最佳:

top - 13:55:27 up 1 day,19:28,2 users,load average: 0.18,0.36,0.19
Tasks:  84 total,1 running,83 sleeping,0 stopped,0 zombie
cpu(s):  0.2%us,0.0%sy,0.0%ni,99.8%id,0.0%wa,0.0%hi,0.0%si,0.0%st
Mem:   3974264k total,1051360k used,2922904k free,162380k buffers
Swap:  3998700k total,0k used,3998700k free,609220k cached

  PID USER      PR  NI  VIRT  RES  Shr S %cpu %MEM    TIME+  COMMAND
 1857 www-data  20   0  193m  55m  22m S    0  1.4   0:04.67 PHP5-fpm
    1 root      20   0  8356  808  680 S    0  0.0   0:01.37 init
    2 root      20   0     0    0    0 S    0  0.0   0:00.00 kthreadd

我认为cpu的使用率现在已经降低了,但这并没有解决崩溃问题……

我的配置现在是:PHP-fpm.conf

;;;;;;;;;;;;;;;;;;;;;
; FPM Configuration ;
;;;;;;;;;;;;;;;;;;;;;

; All relative paths in this configuration file are relative to PHP's install
; prefix (/usr). This prefix can be dynamicaly changed by using the
; '-p' argument From the command line.

; Include one or more files. If glob(3) exists,it is used to include a bunch of
; files from a glob(3) pattern. This directive can be used everywhere in the
; file.
; Relative path can also be used. They will be prefixed by:
;  - the global prefix if it's been set (-p arguement)
;  - /usr otherwise
;include=/etc/PHP5/fpm/*.conf

;;;;;;;;;;;;;;;;;;
; Global Options ;
;;;;;;;;;;;;;;;;;;

[global]
; Pid file
; Note: the default prefix is /VAR
; Default Value: none
pid = /var/run/PHP5-fpm.pid

; Error LOG file
; If it's set to "Syslog",log is sent to syslogd instead of being written
; in a local file.
; Note: the default prefix is /var
; Default Value: log/PHP-fpm.log
error_log = /var/log/PHP5-fpm.log

; syslog_facility is used to specify what type of program is logging the
; message. This lets syslogd specify that messages from different facilities
; will be handled differently.
; See syslog(3) for possible values (ex daemon equiv LOG_DAEMON)
; Default Value: daemon
;syslog.facility = daemon

; syslog_ident is prepended to every message. If you have multiple FPM
; instances running on the same server,you can change the default value
; which must suit common needs.
; Default Value: PHP-fpm
;syslog.ident = PHP-fpm

; Log level
; Possible Values: alert,error,warning,notice,debug
; Default Value: notice
;log_level = notice

; If this number of child processes exit with SIGSEGV or SIGBUS within the time
; interval set by emergency_restart_interval then FPM will restart. A value
; of '0' means 'Off'.
; Default Value: 0
emergency_restart_threshold = 1

; Interval of time used by emergency_restart_interval to determine when 
; a graceful restart will be initiated.  This can be useful to work around
; accidental corruptions in an accelerator's shared memory.
; Available Units: s(econds),m(inutes),h(ours),or d(ays)
; Default Unit: seconds
; Default Value: 0
emergency_restart_interval = 1s

; Time limit for child processes to wait for a reaction on signals from master.
; Available units: s(econds),or d(ays)
; Default Unit: seconds
; Default Value: 0
process_control_timeout = 10s

; The maximum number of processes FPM will fork. This has been design to control
; the global number of processes when using dynamic PM within a lot of pools.
; Use it with caution.
; Note: A value of 0 indicates no limit
; Default Value: 0
process.max = 150

; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
; Default Value: yes
;daemonize = yes

; Set open file descriptor rlimit for the master process.
; Default Value: system defined value
rlimit_files = 1024

; Set max core size rlimit for the master process.
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
;rlimit_core = 0

; Specify the event mechanism FPM will use. The following is available:
; - select     (any posix os)
; - poll       (any POSIX os)
; - epoll      (linux >= 2.5.44)
; - kqueue     (FreeBSD >= 4.1,openbsd >= 2.9,NetBSD >= 2.0)
; - /dev/poll  (solaris >= 7)
; - port       (Solaris >= 10)
; Default Value: not set (auto detection)
; events.mechanism = epoll

;;;;;;;;;;;;;;;;;;;;
; Pool DeFinitions ; 
;;;;;;;;;;;;;;;;;;;;

; Multiple pools of child processes may be started with different listening
; ports and different management options.  The name of the pool will be
; used in logs and stats. There is no limitation on the number of pools which
; FPM can handle. Your system will tell you anyway :)

; To configure the pools it is recommended to have one .conf file per
; pool in the following directory:
include=/etc/PHP5/fpm/pool.d/*.conf

request_terminate_timeout = 30s

pm.max_children = 25

; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 5

; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 2

; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 5

; The number of seconds after which an idle process will be killed.
; Note: Used only when pm is set to 'ondemand'
; Default Value: 10s
pm.process_idle_timeout = 10s;

fastcgi_params:

fastcgi_param   QUERY_STRING        $query_string;
fastcgi_param   REQUEST_METHOD      $request_method;
fastcgi_param   CONTENT_TYPE        $content_type;
fastcgi_param   CONTENT_LENGTH      $content_length;

fastcgi_param   SCRIPT_FILENAME     $request_filename;
fastcgi_param   SCRIPT_NAME     $fastcgi_script_name;
fastcgi_param   REQUEST_URI     $request_uri;
fastcgi_param   DOCUMENT_URI        $document_uri;
fastcgi_param   DOCUMENT_ROOT       $document_root;
fastcgi_param   SERVER_PROTOCOL     $server_protocol;

fastcgi_param   GATEWAY_INTERFACE   CGI/1.1;
fastcgi_param   SERVER_Software     Nginx/$Nginx_version;

fastcgi_param   REMOTE_ADDR     $remote_addr;
fastcgi_param   REMOTE_PORT     $remote_port;
fastcgi_param   SERVER_ADDR     $server_addr;
fastcgi_param   SERVER_PORT     $server_port;
fastcgi_param   SERVER_NAME     $server_name;

#fastcgi_param  HTTPS           $https;

# PHP only,required if PHP was built with --enable-force-cgi-redirect
fastcgi_param   REDIRECT_STATUS     200;

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_intercept_errors on;

Nginx配置:

user www-data;
worker_processes 2;
pid /var/run/Nginx.pid;

events {
    worker_connections 500;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 40;
    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;

    ##
    # 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 9;
 gzip_buffers 16 8k;
 gzip_http_version 1.1;
 gzip_types text/plain text/css application/JSON application/x-javascript text/$

www.conf

; Start a new pool named 'www'.
; the variable $pool can we used in any directive and will be replaced by the
; pool name ('www' here)
[www]

user = www-data
group = www-data


pm = dynamic

pm.max_children = 25

pm.start_servers = 5

pm.min_spare_servers = 2

pm.max_spare_servers = 5

pm.process_idle_timeout = 10s;

pm.max_requests = 100

request_terminate_timeout = 120s

Mashine:
双核
4gb ram

@H_126_38@ 目前尚不清楚您是否正在使用像APC这样的操作码cacher.首先,启用它.调整内存以避免碎片.另外,使用socket,而不是从NginxPHP5-fpm的httP连接,并将该套接字放在/ dev / shm上.
Nginx中,使用fastcgi_pass unix:/dev/shm/PHP5-fpm.sock ;,并相应地更改PHP5-fpm的配置.

尝试将pm.max_children降低到30-40-50-60之间的更逼真的状态,并使用free -m查看负载和空闲内存.查看客户端是否收到任何502/504错误.相应地降低pm.start_servers,min和max_spare(15,5,25).

如果有很多匿名用户,请考虑使用任何缓存插件,如WP-FFPC,WP Super Cache或类似的wordpress.

如果在Nginx中启用了gzip,请禁用gzipping.

也许您需要在Nginx中调整fastcgi_buffer_size和fastcgi_buffers选项.

检查您是否在MysqL上启用了查询缓存并且已经足够.

在网站上安装了像munin这样的监控系统,以检查负载/内存消耗/延迟等.

脚本宝典总结

以上是脚本宝典为你收集整理的Php5-fpm如果有很多访客则会崩溃全部内容,希望文章能够帮你解决Php5-fpm如果有很多访客则会崩溃所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。