首页 > 代码库 > 关于php配置参数

关于php配置参数

没事查看了一下php日志,发现提示进程数不够,日志信息如下:

[04-Nov-2014 14:19:08] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_serve

rs), spawning 8 children, there are 0 idle, and 15 total children

[04-Nov-2014 14:29:27] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_serve

rs), spawning 8 children, there are 0 idle, and 16 total children

[04-Nov-2014 16:51:04] NOTICE: Finishing ...

[04-Nov-2014 16:51:04] NOTICE: exiting, bye-bye!

[04-Nov-2014 16:51:06] NOTICE: fpm is running, pid 31023

[04-Nov-2014 16:51:06] NOTICE: ready to handle connections

[04-Nov-2014 19:01:05] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_serve

rs), spawning 8 children, there are 0 idle, and 17 total children

[04-Nov-2014 19:54:47] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_serve

rs), spawning 8 children, there are 0 idle, and 17 total children

[04-Nov-2014 20:36:06] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_serve

rs), spawning 8 children, there are 0 idle, and 19 total children

[04-Nov-2014 21:18:56] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_serve

rs), spawning 8 children, there are 0 idle, and 17 total children

[05-Nov-2014 05:30:04] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_serve

rs), spawning 8 children, there are 0 idle, and 15 total children

[05-Nov-2014 11:01:37] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_serve

rs), spawning 8 children, there are 0 idle, and 17 total children

[05-Nov-2014 11:01:38] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_serve

rs), spawning 16 children, there are 0 idle, and 21 total children


使用下面的命令查看php进程:

[root@test ~]# ps -ef |grep php

root     25874 20907  0 11:56 pts/0    00:00:00 more index.php

www      26030 31023 32 12:02 ?        00:00:26 php-fpm: pool www                                                                                                               

www      26037 31023 31 12:02 ?        00:00:22 php-fpm: pool www                                                                                                               

www      26042 31023 31 12:02 ?        00:00:20 php-fpm: pool www                                                                                                               

www      26046 31023 30 12:02 ?        00:00:17 php-fpm: pool www                                                                                                               

www      26054 31023 30 12:02 ?        00:00:15 php-fpm: pool www                                                                                                               

www      26059 31023 30 12:02 ?        00:00:14 php-fpm: pool www                                                                                                               

www      26062 31023 30 12:03 ?        00:00:12 php-fpm: pool www                                                                                                               

www      26063 31023 30 12:03 ?        00:00:09 php-fpm: pool www                                                                                                               

www      26066 31023 30 12:03 ?        00:00:09 php-fpm: pool www                                                                                                               

www      26089 31023 23 12:03 ?        00:00:02 php-fpm: pool www                                                                                                               

www      26092 31023 24 12:03 ?        00:00:01 php-fpm: pool www                                                                                                               

root     26097 25911  0 12:03 pts/1    00:00:00 grep php

root     31023     1  0 Nov04 ?        00:00:09 php-fpm: master process (/usr/local/php5/etc/php-fpm.conf)  


内存占用情况:只用了2G左右的内存

[root@test etc]# free -m

             total       used       free     shared    buffers     cached

Mem:         19990      19685        304          0        256      16949

-/+ buffers/cache:       2480      17509

Swap:        19999        112      19887



打开配置文件php-fpm.conf发现:pm.max_children = 5

wKiom1RZ1u3SDyFKAAFuqjFfjAA932.jpg



修改成如下参数后,发现php日志中无此报警了:

; Note: This value is mandatory.

pm.max_children = 1024


; 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 = 512


; 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 = 4


; 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 = 512


查看php-fpm的子进程数,跟配置文件里面设置的一样,等于pm.start_servers+pm.min_spare_servers

[root@test etc]# ps -ef |grep php |wc -l

515

修改php配置文件后,内存占用从2G变成了6.8G左右,增长了4.8G左右,一个php进程开销占到了8M左右,这个可以根据实际的内存情况来进行修改。

[root@localhost log]# free -m

             total       used       free     shared    buffers     cached

Mem:         19990      19438        551          0        189      12414

-/+ buffers/cache:       6835      13154

Swap:        19999        129      19870


补充:

php-fpm有一个参数 max_requests,该参数指明了,每个children最多处理多少个请求后便会被关闭,默认的设置是500。因为php是把请求轮询给每个children,在大流量下,每个childre到达max_requests所用的时间都差不多,这样就造成所有的children基本上在同一时间被关闭,这样会导致此时nginx发给php的请求无法得到相应,会出现短时间的502.解决方法:

增加children的数量,并且将 max_requests 设置未 0 或者一个比较大的值

一般增加max_requests到102400,可能有效果。


本文出自 “运维之道” 博客,谢绝转载!

关于php配置参数