当前位置:网站首页>What are the PHP FPM configuration parameters
What are the PHP FPM configuration parameters
2022-07-01 12:12:00 【Yisu cloud】
PHP FPM What are the configuration parameters
Today I'd like to share with you PHP FPM What are the relevant knowledge points of configuration parameters , Detailed content , Clear logic , I believe most people still know too much about this knowledge , So share this article for your reference , I hope you will gain something after reading this article , Now let's take a look .
PHP-FPM It's a PHP FastCGI Process Manager .FastCGI It's a scalable , At high speed web server Interface with scripting language .FastCGI The main advantages of dynamic language and web server Separate from . This technology allows web server And dynamic languages run on different hosts , Expand and improve security on a large scale without losing productivity .

PHP-FPM Configuration details
FPM The configuration file is php-fpm.conf, Its syntax is similar php.ini .
php-fpm.conf Global configuration section # Include others POOL Define configuration file include=/etc/php-fpm.d/*.conf# Global configuration section , Definition PID The location of the file and the location of the error log [global] daemonize = yes pid = /var/run/php-fpm/php-fpm.pid error_log = /var/log/php-fpm/error.log
Usually in the main configuration file php-fpm.conf There are very few configurations in the global configuration section ,php-fpm You can configure multiple pool, Every pool All operate with a separate configuration file , By default, it will be defined in the main configuration file include Included in the file directory .php A default will be provided www Of pool, The configuration is as follows .
$ cat /etc/php-fpm.d/www.conf [www] user = apache group = apache listen = 127.0.0.1:9000 listen.allowed_clients = 127.0.0.1 pm = dynamic pm.max_children = 50 pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 35
Every pool Configuration file parameters can be independent , It can also be set in the global configuration section of the main configuration file , So each of them pool Just share one parameter . It is recommended to set it separately . The commonly used parameters are as follows :
daemonize = yes
# The background to perform fpm, The default value is yes, If you want to debug, you can change it to no. stay FPM in , You can use different settings to run multiple process pools . These settings can be set individually for each process pool .
listen = 127.0.0.1:9000
#fpm Listening port , namely nginx in php Address of processing , The default value is OK . The available format is : ‘ip:port’, ‘port’, ‘/path/to/unix/socket’, Each process pool needs to be set . If nginx and php On different machines , distributed processing , Is set ip Here it is .
listen.backlog = -1
#backlog Count , Set up listen The length of the semi join queue of ,-1 Means unlimited , It's up to the operating system , Just comment out this line .backlog Refer to :http://www.3gyou.cc/?p=41.
log_level = notice
# error level . above php-fpm.log Registration of records . The available levels are : alert( Must deal with immediately ), error( Wrong situation ), warning( Warning conditions ), notice( General important information ), debug( Debugging information ). Default : notice.
emergency_restart_threshold = 60 emergency_restart_interval = 60s
# It means that emergency_restart_interval Appears in the set value SIGSEGV perhaps SIGBUS FALSE php-cgi If the number of processes exceeds emergency_restart_threshold individual ,php-fpm It will restart gracefully . These two options generally remain the default values .0 Express ‘ Turn off the function ’. The default value is : 0 ( close ).
process_control_timeout = 0
# Set the timeout for the subprocess to accept the multiplexing signal of the main process . Available units : s( second ), m( branch ), h( Hours ), perhaps d( God ) Default unit : s( second ). The default value is : 0.
listen.allowed_clients = 127.0.0.1
# allow access to FastCGI Process IP White list , Set up any For no limit IP, If you want to set other hosts nginx You can also access this FPM process ,listen Place to be set locally accessible IP. The default value is any. Each address is separated by a comma . If not set or empty , Any The server Request connection .
listen.owner = www listen.group = www listen.mode = 0666
#unix socket set an option , If you use tcp Access to , Note here .
user = www group = www
# The user and user group that started the process ,FPM Process running Unix user , You have to set . User group , If not set , The default user's group is used .
pm = dynamic
#php-fpm Process startup mode ,pm It can be set to static and dynamic and ondemand. If you choose static, Then the number of processes is fixed , from pm.max_children Specify a fixed number of subprocesses . If you choose dynamic, Then the number of processes changes dynamically , Determined by the following parameters :
pm.max_children = 50
# The maximum number of child processes that can be opened .
pm.start_servers = 2
# Number of processes at startup , The default value is : min_spare_servers + (max_spare_servers – min_spare_servers) / 2.
pm.min_spare_servers = 1
# Ensure that the minimum number of idle processes , If the idle process is less than this value , Create a new subprocess .
pm.max_spare_servers = 3
# Maximum number of idle processes guaranteed , If the idle process is greater than this value , This is for cleaning .
pm.max_requests = 500
# Set the number of requests served before each subprocess is reborn . It is very useful for third-party modules that may have memory leaks . If set to ‘0’ Always accept the request . Equate to PHP_FCGI_MAX_REQUESTS environment variable . The default value is : 0.
pm.status_path = /status
#FPM Web address of the status page . If not set , Can't access the status page . The default value is : none. munin Monitoring will use
ping.path = /ping
#FPM Monitor the ping website . If not set , Can't access ping page . This page is used for external detection FPM Is it alive and able to respond to requests . Please note that it must start with a slash (/).
ping.response = pong
# Used for definition ping The return of the request corresponds to . Return to HTTP 200 Of text/plain Rich text . The default value is : pong.
access.log = log/$pool.access.log
# Access log for each request , The default is off .
access.format = “%R – %u %t \”%m %r%Q%q\” %s %f %{mili}d %{kilo}M %C%%”
# Set the format of access log .
slowlog = log/$pool.log.slow
# Logging of slow requests , coordination request_slowlog_timeout Use , Off by default
request_slowlog_timeout = 10s
# When a request for this setting timeout , It will correspond to PHP Call stack information is fully written to the slow log . Set to ‘0’ Express ‘Off’
request_terminate_timeout = 0
# Set the timeout stop time for a single request . This option may be for php.ini Set in the ’max_execution_time’ Scripts that do not abort for some special reason are useful . Set to ‘0’ Express ‘Off’. When it comes up often 502 You can try to change this option in case of error .
rlimit_files = 1024
# Set the rlimit Limit . The default value is : The default openable handle for system defined values is 1024, You can use ulimit -n see ,ulimit -n 2048 modify .
rlimit_core = 0
# Setting the core rlimit Maximum limit value . Available value : ‘unlimited’ 、0 Or a positive integer . The default value is : System defined values .
chroot = /data/app
# At startup Chroot Catalog . The defined directory needs to be an absolute path . If not set , be chroot Not used .
chdir = /data/app
# Set startup directory , It will start automatically Chdir Go to the directory . The defined directory needs to be an absolute path . The default value is : Current directory , perhaps / Catalog (chroot when ).
catch_workers_output = yes
# Redirecting in the running process stdout and stderr To the main error log file . If not set , stdout and stderr Will be based on FastCGI Rules that are redirected to /dev/null . The default value is : empty .
Of course, there are some unimportant settings , Let's talk about it when it's used .
PHP-FPM Important settings
php-fpm Process assignment
It was said in the previous article . stay fasgcgi In mode ,php It starts multiple php-fpm process , To receive nginx A request from , Is that the more progress , The faster the speed ? It doesn't have to be ! It depends on our machine configuration and business volume .
So let's see , Set the configuration of the process ?
pm = static | dynamic | ondemand pm It can be set like this 3 Kind of , The one we use most is the front 2 Kind of . pm = static Pattern pm = static Represents what we created php-fpm The number of child processes is fixed , So there's only pm.max_children = 50 This parameter takes effect . You start php-fpm Will start all together 51(1 Owners +50 Height ) A process , Very spectacular . pm = dynamic Pattern pm = dynamic Pattern , Indicates that the startup process is dynamically allocated , Dynamically changing with the amount of requests . He is made up of pm.max_children,pm.start_servers,pm.min_spare_servers,pm.max_spare_servers These parameters jointly determine . It's already said , Here again : pm.max_children = 50 Is the maximum number of child processes that can be created . You have to set . It means at most 50 Subprocess . pm.start_servers = 20 With php-fpm Number of child processes created when started together . The default value is :min_spare_servers + (max_spare_servers – min_spare_servers) / 2. It means , Starting together will have 20 Subprocess . pm.min_spare_servers = 10 Set the server idle minimum php-fpm Number of processes . You have to set . If in your spare time , Will check if less than 10 individual , We'll start a few to make it up . pm.max_spare_servers = 30 Set the maximum when the server is idle php-fpm Number of processes . You have to set . If you're free , Will check the number of processes , More than 30 A the , It'll shut down a few , achieve 30 Status of .
The general principle is : Dynamic suitable for small memory machines , Flexible allocation of processes , Provincial memory . Static is suitable for large memory machines , Dynamically creating a recycling process is also a consumption of server resources .
If you have a lot of memory , Yes 8-20G, According to one php-fpm process 20M count ,100 A is 2G The memory , Then you can open static Pattern . If your memory is small , For example, only 256M, Then set it carefully , Because other processes in your machine also need to occupy memory , So set it to dynamic It's the best , such as :pm.max_chindren = 8, Take up memory 160M about , And it can change at any time , It's enough for a website with half the traffic .
Slow log query
Sometimes we often suffer 500,504 Trouble . When nginx When receiving the above error code , You can determine the backend php-fpm analysis php Something went wrong , such as , Perform error , Execution timeout .
This is the time , We can turn on the slow log function .
slowlog = /usr/local/var/log/php-fpm.log.slow request_slowlog_timeout = 15s
When a request for the set timeout 15 Seconds later , It will correspond to PHP Call stack information is fully written to the slow log .
php-fpm The slow log will record the process number , Script name , Which specific file, which line of code, which function takes too long to execute :
[21-Nov-2013 14:30:38] [pool www] pid 11877 script_filename = /usr/local/lnmp/nginx/html/www.quancha.cn/www/fyzb.php [0xb70fb88c] file_get_contents() /usr/local/lnmp/nginx/html/www.quancha.cn/www/fyzb.php:2
Through the log , We can know the first 2 Yes file_get_contents There's something wrong with the function , So we can track the problem .
That's all “PHP FPM What are the configuration parameters ” All the content of this article , Thank you for reading ! I believe you will gain a lot after reading this article , Xiaobian will update different knowledge for you every day , If you want to learn more , Please pay attention to the Yisu cloud industry information channel .
边栏推荐
- The operation process of using sugar to make a large data visualization screen
- Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
- How does Nike dominate the list all the year round? Here comes the answer to the latest financial report
- Unity xlua co process packaging
- Acly and metabolic diseases
- 谈思生物直播—GENOVIS张洪妍抗体特异性酶切技术助力抗体药物结构表征
- 用实际例子详细探究OpenCV的轮廓检测函数findContours(),彻底搞清每个参数、每种模式的真正作用与含义
- 耐克如何常年霸榜第一名?最新財報答案來了
- 技术分享 | MySQL:从库复制半个事务会怎么样?
- 顺序表有关操作
猜你喜欢
[106] 360 check font - check whether the copyright of local Fonts is commercially available
Abbirb120 industrial robot mechanical zero position
Istio、eBPF 和 RSocket Broker:深入研究服务网格
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 5
Leetcode force buckle (Sword finger offer 31-35) 31 Stack push pop-up sequence 32i II. 3. Print binary tree from top to bottom 33 Post order traversal sequence 34 of binary search tree The path with a
被锡膏坑了一把
循环链表--
[MCU] [nixie tube] nixie tube display
强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐
【datawhale202206】pyTorch推荐系统:召回模型 DSSM&YoutubeDNN
随机推荐
循环链表--
Message queue monitoring refund task batch process
uniapp 使用 uni-upgrade-center
MQ prevent message loss and repeated consumption
谈思生物直播—GENOVIS张洪妍抗体特异性酶切技术助力抗体药物结构表征
Le semester manquant
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 6
比特熊直播间一周年,英雄集结令!邀你来合影!
指定的服务已标记为删除
C # dependency injection (straight to the point) will be explained as soon as you see the series
Computer graduation project asp Net hotel room management system VS development SQLSERVER database web structure c programming computer web page source code project
S7-1500plc simulation
Building external modules
图的理论基础
Typora adds watermarks to automatically uploaded pictures
Onenet Internet of things platform - create mqtts products and devices
顺序表有关操作
[MCU] [nixie tube] nixie tube display
栈-------
Seckill system 03 - redis cache and distributed lock