php-fpm

news/2025/2/21 17:01:59/

摘要

php-fpm(fastcgi process manager)是PHP 的FastCGI管理器,管理PHP的FastCGI进程,提升PHP应用的性能和稳定性

php-fpm是一个高性能的php FastCGI管理器,提供了更好的php进程管理方式,可以有效的控制内存和进程,支持平滑重载php配置。PHP-FPM使用FastCGI协议与web服务器(例如:Nginx,Apache)进行通信,采用多进程模型进行处理PHP请求,管理worker进程的生命周期。
 当Web服务器接受到一个php请求时,会将该请求转发到php-fpm(可是使用网络地址(IP:端口)或者是一个Unix套接字(socket)文件),PHP-FPM会根据配置文件(php-fpm.conf)中的参数来创建,管理,回收php解释器进程(worker进程)----此过程为进程管理。并将请求法分配给这些worker进程来处理。

接收FastCGI请求的地址

php-fpm.conf配置文件的进程池配置段中设置 listen配置项

php-fpm进程管理

; 选择进程管理器将如何控制子进程的数量。
; 选项:
;   static  - 静态模式  a fixed number (pm.max_children) of child processes;
;             php-fpm进程启动时,会根据px.max_children数量的进程
;   dynamic - 动态模式
;             子进程(work)进程的数量是根据以下配置设置的,使用此进程管理,将始终至少有一个子进程
;             pm.max_children      - 最大子进程(work)数量
;             pm.start_servers     - php-fpm进程启动时,创建的进程数量
;             pm.min_spare_servers - 设置最小空闲子进程数。当空闲进程数少于这个值时,PHP-FPM会创建新的子进程。
;             pm.max_spare_servers - 设置最大空闲子进程数。当空闲进程数多于这个值时,PHP-FPM会销毁多余的子进程。
;             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 - 按需模式:php-fpm启动时不会创建任何worker进程,仅在有请求进来时创建.进程数受限于process.max和pm.max_children
;             当空闲worker进程超过pm.process_idle_timeout时间未处理请求,则会被销毁
;             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.
; 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 = 8; 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 = 20; 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 = 5; 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 = 35; 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;;用于设置每个 PHP-FPM worker 进程在重启之前最大处理的请求数。具体来说,pm.max_requests 控制了每个 PHP-FPM worker 进程在处理了多少个请求后会被自动终止,并且 PHP-FPM 会启动一个新的 worker 进程来接替它继续处理请求。
; 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 = 10000


http://www.ppmy.cn/news/1573933.html

相关文章

【算法题】1749. 任意子数组和的绝对值的最大值(LeetCode)

【算法题】1749. 任意子数组和的绝对值的最大值(LeetCode) 1.题目 下方是力扣官方题目的地址 1749. 任意子数组和的绝对值的最大值 给你一个整数数组 nums 。一个子数组 [numsl, numsl1, ..., numsr-1, numsr] 的 和的绝对值 为 abs(numsl numsl1 ... numsr-1 numsr) 。…

《从入门到精通:蓝桥杯编程大赛知识点全攻略》(十五)-股票买卖、货仓选址、等差数列、鸣人的影分身

前言 在这篇博客中,我们将深入探讨几种经典的算法问题,并提供相应的求解方法。我们将首先学习如何通过贪心算法来解决股票买卖和货仓选址问题。接着,我们会通过最大公约数来探讨等差数列的求解方法。最后,我们会利用动态规划来解…

线程池工具类:简化并发编程,提升任务执行效率

文章目录 线程池工具类:简化并发编程,提升任务执行效率线程池工具类的设计目标线程池工具类的实现工具类的使用示例1. 提交任务2. 监控线程池状态3. 关闭线程池 工具类的核心功能总结 线程池工具类:简化并发编程,提升任务执行效率…

基于腾讯云大模型知识引擎×DeepSeek构建八字、六爻赛博算卦娱乐应用

引言 随着DeepSeek的火爆,其强大的思维链让不少人越用越香,由于其缜密的思维和推理能力,不少人开发出了不少花里胡哨的玩法,其中一种就是以八字、六爻为代表的玄学文化正以“赛博玄学”的新形态席卷年轻群体。 针对于八字、六爻…

QT事件循环

文章目录 主事件循环事件循环事件调度器事件处理投递事件发送事件 事件循环的嵌套线程的事件循环deleteLater与事件循环QEventLoop类QEventLoop应用等待一段时间同步操作模拟模态对话框 参考 本文主要对QT中的事件循环做简单介绍和使用 Qt作为一个跨平台的UI框架,其…

Python安装与环境配置全程详细教学(包含Windows版和Mac版)

Windows版 Python的安装与环境配置 1.下载Python Python下载地址:Download Python | Python.org 可以在这里直接点击下载,就会下载你电脑对应的最新版本 如果你要是不想下载对应的最新版或者因为某些原因你想安装某一特定版本的Python你可以在上面的…

arm环境下,wpa_supplicant交叉编译+wifi sta连接详解

1、前言 wpa_supplicant 是一个用于 WiFi 客户端的加密认证工具,支持 WEP、WPA、WPA2 等多种加密方式。它通常与 wpa_cli 配合使用,用于管理 WiFi 连接。本文讲解wpa_supplicant 交叉编译全过程以及开发板使用wpa_supplican和udhcpc连接wifi全过程详解。…

第十二届先进制造技术与材料工程国际学术会议 (AMTME 2025)

重要信息 大会官网:www.amtme.org(了解会议,投稿等) 大会时间:2025年3月21-23日 大会地点:中国-广州 简介 2025年第十二届先进制造技术与材料工程 (AMTME 2025) 定于2025年3月21-23日在中国广州隆重举…