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

前端之家收集整理的这篇文章主要介绍了Php5-fpm如果有很多访客则会崩溃前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我决定将我的OP从Litespeed改为Nginx因为我读了很多关于Nginx会花费的资源.

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

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

我也有一些问题:

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

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

  1. top - 13:55:27 up 1 day,19:28,2 users,load average: 0.18,0.36,0.19
  2. Tasks: 84 total,1 running,83 sleeping,0 stopped,0 zombie
  3. 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
  4. Mem: 3974264k total,1051360k used,2922904k free,162380k buffers
  5. Swap: 3998700k total,0k used,3998700k free,609220k cached
  6.  
  7. PID USER PR NI VIRT RES SHR S %cpu %MEM TIME+ COMMAND
  8. 1857 www-data 20 0 193m 55m 22m S 0 1.4 0:04.67 PHP5-fpm
  9. 1 root 20 0 8356 808 680 S 0 0.0 0:01.37 init
  10. 2 root 20 0 0 0 0 S 0 0.0 0:00.00 kthreadd

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

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

  1. ;;;;;;;;;;;;;;;;;;;;;
  2. ; FPM Configuration ;
  3. ;;;;;;;;;;;;;;;;;;;;;
  4.  
  5. ; All relative paths in this configuration file are relative to PHP's install
  6. ; prefix (/usr). This prefix can be dynamicaly changed by using the
  7. ; '-p' argument from the command line.
  8.  
  9. ; Include one or more files. If glob(3) exists,it is used to include a bunch of
  10. ; files from a glob(3) pattern. This directive can be used everywhere in the
  11. ; file.
  12. ; Relative path can also be used. They will be prefixed by:
  13. ; - the global prefix if it's been set (-p arguement)
  14. ; - /usr otherwise
  15. ;include=/etc/PHP5/fpm/*.conf
  16.  
  17. ;;;;;;;;;;;;;;;;;;
  18. ; Global Options ;
  19. ;;;;;;;;;;;;;;;;;;
  20.  
  21. [global]
  22. ; Pid file
  23. ; Note: the default prefix is /var
  24. ; Default Value: none
  25. pid = /var/run/PHP5-fpm.pid
  26.  
  27. ; Error log file
  28. ; If it's set to "syslog",log is sent to syslogd instead of being written
  29. ; in a local file.
  30. ; Note: the default prefix is /var
  31. ; Default Value: log/PHP-fpm.log
  32. error_log = /var/log/PHP5-fpm.log
  33.  
  34. ; syslog_facility is used to specify what type of program is logging the
  35. ; message. This lets syslogd specify that messages from different facilities
  36. ; will be handled differently.
  37. ; See syslog(3) for possible values (ex daemon equiv LOG_DAEMON)
  38. ; Default Value: daemon
  39. ;syslog.facility = daemon
  40.  
  41. ; syslog_ident is prepended to every message. If you have multiple FPM
  42. ; instances running on the same server,you can change the default value
  43. ; which must suit common needs.
  44. ; Default Value: PHP-fpm
  45. ;syslog.ident = PHP-fpm
  46.  
  47. ; Log level
  48. ; Possible Values: alert,error,warning,notice,debug
  49. ; Default Value: notice
  50. ;log_level = notice
  51.  
  52. ; If this number of child processes exit with SIGSEGV or SIGBUS within the time
  53. ; interval set by emergency_restart_interval then FPM will restart. A value
  54. ; of '0' means 'Off'.
  55. ; Default Value: 0
  56. emergency_restart_threshold = 1
  57.  
  58. ; Interval of time used by emergency_restart_interval to determine when
  59. ; a graceful restart will be initiated. This can be useful to work around
  60. ; accidental corruptions in an accelerator's shared memory.
  61. ; Available Units: s(econds),m(inutes),h(ours),or d(ays)
  62. ; Default Unit: seconds
  63. ; Default Value: 0
  64. emergency_restart_interval = 1s
  65.  
  66. ; Time limit for child processes to wait for a reaction on signals from master.
  67. ; Available units: s(econds),or d(ays)
  68. ; Default Unit: seconds
  69. ; Default Value: 0
  70. process_control_timeout = 10s
  71.  
  72. ; The maximum number of processes FPM will fork. This has been design to control
  73. ; the global number of processes when using dynamic PM within a lot of pools.
  74. ; Use it with caution.
  75. ; Note: A value of 0 indicates no limit
  76. ; Default Value: 0
  77. process.max = 150
  78.  
  79. ; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
  80. ; Default Value: yes
  81. ;daemonize = yes
  82.  
  83. ; Set open file descriptor rlimit for the master process.
  84. ; Default Value: system defined value
  85. rlimit_files = 1024
  86.  
  87. ; Set max core size rlimit for the master process.
  88. ; Possible Values: 'unlimited' or an integer greater or equal to 0
  89. ; Default Value: system defined value
  90. ;rlimit_core = 0
  91.  
  92. ; Specify the event mechanism FPM will use. The following is available:
  93. ; - select (any POSIX os)
  94. ; - poll (any POSIX os)
  95. ; - epoll (linux >= 2.5.44)
  96. ; - kqueue (FreeBSD >= 4.1,OpenBSD >= 2.9,NetBSD >= 2.0)
  97. ; - /dev/poll (Solaris >= 7)
  98. ; - port (Solaris >= 10)
  99. ; Default Value: not set (auto detection)
  100. ; events.mechanism = epoll
  101.  
  102. ;;;;;;;;;;;;;;;;;;;;
  103. ; Pool Definitions ;
  104. ;;;;;;;;;;;;;;;;;;;;
  105.  
  106. ; Multiple pools of child processes may be started with different listening
  107. ; ports and different management options. The name of the pool will be
  108. ; used in logs and stats. There is no limitation on the number of pools which
  109. ; FPM can handle. Your system will tell you anyway :)
  110.  
  111. ; To configure the pools it is recommended to have one .conf file per
  112. ; pool in the following directory:
  113. include=/etc/PHP5/fpm/pool.d/*.conf
  114.  
  115. request_terminate_timeout = 30s
  116.  
  117. pm.max_children = 25
  118.  
  119. ; The number of child processes created on startup.
  120. ; Note: Used only when pm is set to 'dynamic'
  121. ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
  122. pm.start_servers = 5
  123.  
  124. ; The desired minimum number of idle server processes.
  125. ; Note: Used only when pm is set to 'dynamic'
  126. ; Note: Mandatory when pm is set to 'dynamic'
  127. pm.min_spare_servers = 2
  128.  
  129. ; The desired maximum number of idle server processes.
  130. ; Note: Used only when pm is set to 'dynamic'
  131. ; Note: Mandatory when pm is set to 'dynamic'
  132. pm.max_spare_servers = 5
  133.  
  134. ; The number of seconds after which an idle process will be killed.
  135. ; Note: Used only when pm is set to 'ondemand'
  136. ; Default Value: 10s
  137. pm.process_idle_timeout = 10s;

fastcgi_params:

  1. fastcgi_param QUERY_STRING $query_string;
  2. fastcgi_param REQUEST_METHOD $request_method;
  3. fastcgi_param CONTENT_TYPE $content_type;
  4. fastcgi_param CONTENT_LENGTH $content_length;
  5.  
  6. fastcgi_param SCRIPT_FILENAME $request_filename;
  7. fastcgi_param SCRIPT_NAME $fastcgi_script_name;
  8. fastcgi_param REQUEST_URI $request_uri;
  9. fastcgi_param DOCUMENT_URI $document_uri;
  10. fastcgi_param DOCUMENT_ROOT $document_root;
  11. fastcgi_param SERVER_PROTOCOL $server_protocol;
  12.  
  13. fastcgi_param GATEWAY_INTERFACE CGI/1.1;
  14. fastcgi_param SERVER_SOFTWARE Nginx/$Nginx_version;
  15.  
  16. fastcgi_param REMOTE_ADDR $remote_addr;
  17. fastcgi_param REMOTE_PORT $remote_port;
  18. fastcgi_param SERVER_ADDR $server_addr;
  19. fastcgi_param SERVER_PORT $server_port;
  20. fastcgi_param SERVER_NAME $server_name;
  21.  
  22. #fastcgi_param HTTPS $https;
  23.  
  24. # PHP only,required if PHP was built with --enable-force-cgi-redirect
  25. fastcgi_param REDIRECT_STATUS 200;
  26.  
  27. fastcgi_connect_timeout 60;
  28. fastcgi_send_timeout 180;
  29. fastcgi_read_timeout 180;
  30. fastcgi_buffer_size 128k;
  31. fastcgi_buffers 4 256k;
  32. fastcgi_busy_buffers_size 256k;
  33. fastcgi_temp_file_write_size 256k;
  34. fastcgi_intercept_errors on;

Nginx配置:

  1. user www-data;
  2. worker_processes 2;
  3. pid /var/run/Nginx.pid;
  4.  
  5. events {
  6. worker_connections 500;
  7. # multi_accept on;
  8. }
  9.  
  10. http {
  11.  
  12. ##
  13. # Basic Settings
  14. ##
  15.  
  16. sendfile on;
  17. tcp_nopush on;
  18. tcp_nodelay on;
  19. keepalive_timeout 40;
  20. types_hash_max_size 2048;
  21. server_tokens off;
  22.  
  23. # server_names_hash_bucket_size 64;
  24. # server_name_in_redirect off;
  25.  
  26. include /etc/Nginx/mime.types;
  27. default_type application/octet-stream;
  28.  
  29. ##
  30. # Logging Settings
  31. ##
  32.  
  33. # access_log /var/log/Nginx/access.log;
  34. # error_log /var/log/Nginx/error.log;
  35.  
  36. ##
  37. # Gzip Settings
  38. ##
  39.  
  40. gzip on;
  41. gzip_disable "msie6";
  42.  
  43. gzip_vary on;
  44. gzip_proxied any;
  45. gzip_comp_level 9;
  46. gzip_buffers 16 8k;
  47. gzip_http_version 1.1;
  48. gzip_types text/plain text/css application/json application/x-javascript text/$

www.conf

  1. ; Start a new pool named 'www'.
  2. ; the variable $pool can we used in any directive and will be replaced by the
  3. ; pool name ('www' here)
  4. [www]
  5.  
  6. user = www-data
  7. group = www-data
  8.  
  9.  
  10. pm = dynamic
  11.  
  12. pm.max_children = 25
  13.  
  14. pm.start_servers = 5
  15.  
  16. pm.min_spare_servers = 2
  17.  
  18. pm.max_spare_servers = 5
  19.  
  20. pm.process_idle_timeout = 10s;
  21.  
  22. pm.max_requests = 100
  23.  
  24. request_terminate_timeout = 120s

Mashine:
双核
4gb ram

目前尚不清楚您是否正在使用像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这样的监控系统,以检查负载/内存消耗/延迟等.

猜你在找的PHP相关文章