欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Linux平台PHP5.4设置FPM线程数量的方法

程序员文章站 2024-03-03 22:28:10
本文实例讲述了linux平台php5.4设置fpm线程数量的方法。分享给大家供大家参考,具体如下: php5.4安装完毕后,fpm的默认配置文件位于/usr/local/...

本文实例讲述了linux平台php5.4设置fpm线程数量的方法。分享给大家供大家参考,具体如下:

php5.4安装完毕后,fpm的默认配置文件位于/usr/local/php/etc/php-fpm.conf.default

>cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
>vim /usr/local/php/etc/php-fpm.conf

输入”/www”,搜索www所在的pool

pm = dynamic
; the number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
; this value sets the limit on the number of simultaneous requests that will be
; served. equivalent to the apachemaxclients directive with mpm_prefork.
; equivalent to the php_fcgi_children environment variable in the original php
; cgi. the below defaults are based on a server without much resources. don't
; forget to tweak pm.* to fit your needs.
; note: used when pm is set to 'static', 'dynamic' or 'ondemand'
; note: this value is mandatory.
pm.max_children = 5
; 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 = 2
; 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 = 1
; 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 = 3
; 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;
; the number of requests each child process should execute before respawning.
; this can be useful to work around memory leaks in 3rd party libraries. for
; endless request processing specify '0'. equivalent to php_fcgi_max_requests.
; default value: 0
;pm.max_requests = 500

解释一下:

pm = dynamic 如何控制子进程,选项有static和dynamic,默认采用dynamic;如果选择static,则由pm.max_children指定固定的子进程数。

如果选择dynamic,则由以下参数决定:

pm.max_children 子进程最大数
pm.start_servers 启动时的进程数
pm.min_spare_servers 保证空闲进程数最小值,如果空闲进程小于此值,则创建新的子进程
pm.max_spare_servers 保证空闲进程数最大值,如果空闲进程大于此值,则进行清理。对于专用服务器,pm可以设置为static。
pm.max_requests 设置每个子进程重生之前服务的请求数. 对于可能存在内存泄漏的第三方模块来说是非常有用的. 如果设置为 '0′ 则一直接受请求. 设置为500就可以了(默认0)。

将值修改为如下:

pm.max_children = 32
pm.start_servers = 16
pm.min_spare_servers = 8
pm.max_spare_servers = 32
pm.max_requests = 500

:wq 保存退出vim

>/usr/local/php/sbin/php-fpm -t
notice: configuration file /usr/local/php/etc/php-fpm.conf test is successful

测试配置文件是否正常,没问题,杀掉当前的fpm进程

>/usr/local/php/sbin/php-fpm

启动

更多关于php相关内容感兴趣的读者可查看本站专题:《php程序设计安全教程》、《php面向对象程序设计入门教程》、《php数学运算技巧总结》、《php数组(array)操作技巧大全》、《php字符串(string)用法总结》、《php数据结构与算法教程》、《php程序设计算法总结》及《php常见数据库操作技巧汇总

希望本文所述对大家php程序设计有所帮助。