찾다
백엔드 개발PHP7FPM의 잘 알려지지 않은 세 가지 모드

우리는 php-fpm을 자주 사용하지만, fpm에 세 가지 모드가 있다는 사실을 모두가 아는 것은 아닙니다. 오늘 Xiaonian은 필요한 경우 참조할 수 있도록 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에는 정적, 동적 및 ondemand의 세 가지 모드가 있습니다.

static

이 방법은 시작 시 비교적 간단합니다. 마스터는 pm.max_children 구성에 따라 해당 수의 작업자 프로세스를 분기합니다. 즉, 작업자 프로세스 수가 고정되어 있습니다.

dynamic

동적 프로세스 관리, 먼저 fpm이 시작될 때 pm.start_servers에 따라 특정 수의 작업자를 초기화합니다.

작업 중에 마스터가 유휴 작업자 수가 구성된 pm.min_spare_servers 수보다 적음을 발견하면(요청이 너무 많아 작업자가 이를 처리할 수 없음을 나타냄) 작업자 프로세스를 포크하지만 총 작업자 수는 pm.max_children을 초과할 수 없습니다.

마스터가 유휴 작업자 수가 pm.max_spare_servers를 초과하는 것을 발견하면(유휴 작업자가 너무 많다는 것을 나타냄) 너무 많은 리소스를 점유하지 않도록 일부 작업자를 종료합니다. 마스터는 이 4가지 값을 통해 작업자 수를 제어합니다. .

ondemand

이 방법은 일반적으로 시작 시 작업자 프로세스가 할당되지 않습니다. 마스터 프로세스는 요청이 있는 후 작업자 프로세스를 포크하도록 알림을 받습니다. 이후에는 총 작업자 수가 pm.max_children을 초과하지 않습니다. 처리가 완료되면 작업자 프로세스는 즉시 종료되고 유휴 시간이 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 reloadphp-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 stop

kill SIGUSR1 php-fpm 재사용 새 파일, 로그 자르기 완료kill SIGUSR2 php-fpm 작업 프로세스를 다시 시작하고 구성 파일을 다시 로드합니다

🎜Q1: php-fpm 프로세스를 시작한 후 php-fpm 마스터 프로세스 번호를 종료하고 반환할 수 있습니다. 서비스는 계속되나요? A: 아니요(모든 php-fpm 프로세스가 종료됩니다.)🎜🎜Q2: php-fpm 프로세스를 시작한 후 kill -9 php-fpm 마스터 프로세스 번호, 서비스를 계속할 수 있나요? A: 예(마스터 프로세스만 종료되고 작업 프로세스는 계속 작동 중입니다.) 🎜🎜Q2: php-fpm 프로세스를 시작한 후 php-fpm 작업 프로세스 번호를 종료합니다. 서비스를 계속할 수 있나요? A: 예(작업 프로세스가 종료된 후 새로운 작업 프로세스가 시작됩니다)🎜🎜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 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명
이 기사는 CSDN에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

SublimeText3 Linux 새 버전

SublimeText3 Linux 새 버전

SublimeText3 Linux 최신 버전

ZendStudio 13.5.1 맥

ZendStudio 13.5.1 맥

강력한 PHP 통합 개발 환경

에디트플러스 중국어 크랙 버전

에디트플러스 중국어 크랙 버전

작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

맨티스BT

맨티스BT

Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.