登录  /  注册
首页 > 后端开发 > PHP7 > 正文

FPM鲜为人知的三种模式

醉折花枝作酒筹
发布: 2021-07-21 09:39:46
转载
1934人浏览过

我们经常使用php-fpm,但是不一定所有人都知道fpm有三种模式,今天小年就带大家了解一下fpm的三种模式,有需要的可以参考参考。

FPM鲜为人知的三种模式

; Choose how the process manager will control the number of child processes.
; Possible Values:
;   static  - a fixed number (pm.max_children) of child processes;
;   dynamic - the number of child processes are set dynamically based on the
;             following directives. With this process management, there will be
;             always at least 1 children.
;             pm.max_children      - the maximum number of children that can
;                                    be alive at the same time.
;             pm.start_servers     - the number of children created on startup.
;             pm.min_spare_servers - the minimum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is less than this
;                                    number then some children will be created.
;             pm.max_spare_servers - the maximum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is greater than this
;                                    number then some children will be killed.
;  ondemand - no children are created at startup. Children will be forked when
;             new requests will connect. The following parameter are used:
;             pm.max_children           - the maximum number of children that
;                                         can be alive at the same time.
;             pm.process_idle_timeout   - The number of seconds after which
;                                         an idle process will be killed.
; Note: This value is mandatory.
登录后复制

pm有三种模式:static、dynamic和ondemand

static

这种方式比较简单,在启动时master按照pm.max_children配置fork出相应数量的worker进程,即worker进程数是固定不变的。

dynamic

动态进程管理,首先在fpm启动时按照pm.start_servers初始化一定数量的worker。

运行期间如果master发现空闲worker数低于pm.min_spare_servers配置数(表示请求比较多,worker处理不过来了)则会fork worker进程,但总的worker数不能超过pm.max_children。

如果master发现空闲worker数超过了pm.max_spare_servers(表示闲着的worker太多了)则会杀掉一些worker,避免占用过多资源,master通过这4个值来控制worker数。

ondemand

这种方式一般很少用,在启动时不分配worker进程,等到有请求了后再通知master进程fork worker进程,总的worker数不超过pm.max_children,处理完成后worker进程不会立即退出,当空闲时间超过pm.process_idle_timeout后再退出。

pm.max_children:静态方式下开启的php-fpm进程数量。

pm.start_servers:动态方式下的起始php-fpm进程数量。

pm.min_spare_servers:动态方式下的最小php-fpm进程数量。

pm.max_spare_servers:动态方式下的最大php-fpm进程数量。

FPM对信号的处理

php-fpm reload

php-fpm stop

kill SIGUSR1 php-fpm 重新使用新的文件,完成日志切割

kill SIGUSR2 php-fpm 重新启动work进程,重新加载配置文件

Q1:启动php-fpm进程之后,kill php-fpm master进程号,还能继续服务吗? A: 不能 (所有php-fpm进程都被关闭)

Q2:启动php-fpm进程之后,kill -9 php-fpm master进程号,还能继续服务吗? A: 能(只kill了 master进程,work进程还在工作)

Q2:启动php-fpm进程之后,kill php-fpm work进程号,还能继续服务吗?A: 能(work进程被kill后,又新起一个work进程)

FPM的生命周期

php_module_startup()

fcgi_accept_request()

php_request_startup()

fmp_request_executing()

php_execute_script()

fpm_requset_end()

php_request_shutdown()

因为fpm是常驻进程,所以在php_request_shutdown()之后又会从fcgi_accept_request()开始循环。

推荐学习:php视频教程

以上就是FPM鲜为人知的三种模式的详细内容,更多请关注php中文网其它相关文章!

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
来源:CSDN网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号