php-fpm配置文件详解
第一部分:FPM 配置
参数 | 说明
-p | 命令行中动态修改--prefix
;include=etc/fpm.d/*.conf | 用于包含一个或多个文件,如果glob(3)存在(glob()函数返回匹配指定模式的文件名或目录)
第二部分:全局配置
由标志[global]开始:
;pid = run/php-fpm.pid 设置pid文件的位置,默认目录路径 /usr/local/php/var
;error_log = log/php-fpm.log 记录错误日志的文件,默认目录路径 /usr/local/php/var
;syslog.facility = daemon 用于指定什么类型的程序日志消息。
;syslog.ident = php-fpm 用于FPM多实例甄别
;log_level = notice 记录日志的等级,默认notice,可取值alert, error, warning, notice, debug
;emergency_restart_threshold = 0 如果子进程在这个时间段内带有IGSEGV或SIGBUS退出,则重启fpm,默认0表示关闭这个功能
;emergency_restart_interval = 0 设置时间间隔来决定服务的初始化时间(默认单位:s秒),可选s秒,m分,h时,d天
;process_control_timeout = 0 子进程等待master进程对信号的回应(默认单位:s秒),可选s秒,m分,h时,d天
; process.max = 128 控制最大进程数,使用时需谨慎
; process.priority = -19 处理nice(2)的进程优先级别-19(最高)到20(最低)
;rlimit_files = 1024 设置主进程文件描述符rlimit的数量
;rlimit_core = 0 设置主进程rlimit最大核数
;events.mechanism = epoll 使用处理event事件的机制
; - select (any POSIX os)
; - poll (any POSIX os)
; - epoll (linux >= 2.5.44)
; - kqueue (FreeBSD >= 4.1, OpenBSD >= 2.9, NetBSD >= 2.0)
; - /dev/poll (Solaris >= 7)
; - port (Solaris >= 10)
;daemonize = yes 将fpm转至后台运行,如果设置为“no”,那么fpm会运行在前台
;systemd_interval = 10
第三部分:进程池的定义
通过监听不同的端口和不用管理选择可以定义多个不同的子进程池,进程池被用与记录和统计,对于fpm能够处理进程池数目的多少并没有限制
其中$pool变量可以在任何指令中使用,他将会替代相应的进程池名字。例如:这里的[www]
[root@test ~]# ps -ef | grep php-fpm
root : ? :: php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nobody : ? :: php-fpm: pool www
nobody : ? :: php-fpm: pool www
[www]
; It only applies on the following directives:
; - 'access.log'
; - 'slowlog'
; - 'listen' (unixsocket)
; - 'chroot'
; - 'chdir'
; - 'php_values'
; - 'php_admin_values' ;prefix = /path/to/pools/$pool 如果没有制定,将使用全局prefix替代
user = nobody 进程的发起用户和用户组,用户user是必须设置,group不是
group = nobody
listen = 127.0.0.1:9000 监听ip和端口
;listen.backlog = 65535 设置listen(2)函数backlog
;listen.owner = nobody
;listen.group = nobody
;listen.mode = 0660
;listen.acl_users =
;listen.acl_groups =
;listen.allowed_clients = 127.0.0.1 允许FastCGI客户端连接的IPv4地址,多个地址用','分隔,为空则允许任何地址发来链接请求
; process.priority = -19
pm = dynamic 选择进程池管理器如何控制子进程的数量
static: 对于子进程的开启数路给定一个锁定的值(pm.max_children)
dynamic: 子进程的数目为动态的,它的数目基于下面的指令的值(以下为dynamic适用参数)
pm.max_children: 同一时刻能够存货的最大子进程的数量
pm.start_servers: 在启动时启动的子进程数量
pm.min_spare_servers: 处于空闲"idle"状态的最小子进程,如果空闲进程数量小于这个值,那么相应的子进程会被创建
pm.max_spare_servers: 最大空闲子进程数量,空闲子进程数量超过这个值,那么相应的子进程会被杀掉。
ondemand: 在启动时不会创建,只有当发起请求链接时才会创建(pm.max_children, pm.process_idle_timeout) pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
;pm.process_idle_timeout = 10s; 空闲进程超时时间
;pm.max_requests = 500 在派生新的子进程前,每一个子进程应该处理的请求数目,在第三方库中解决内存溢出很有用,设置为0则不会限制
;pm.status_path = /status 配置一个URI,以便查看fpm状态页
状态页描述:
accepted conn: 该进程池接受的请求数量
pool: 进程池的名字
process manager: 进程管理,就是配置中pm指令,可以选择值static,dynamic,ondemand
idle processes: 空闲进程数量
active processes: 当前活跃的进程数量
total processes: 总的进程数量=idle+active
max children reached: 达到最大子进程的次数,达到进程的限制,当pm试图开启更多的子进程的时候(仅当pm工作在dynamic时)
;ping.path = /ping 该ping URI将会去调用fpm监控页面,如果这个没有设置,那么不会有URI被做为ping页
;ping.response = pong 用于定制平请求的响应,响应的格式text/plain(对200响应代码)
;access.log = log/$pool.access.log
;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"
; The following syntax is allowed
; %%: the '%' character
; %C: %CPU used by the request
; it can accept the following format:
; - %{user}C for user CPU only
; - %{system}C for system CPU only
; - %{total}C for user + system CPU (default)
; %d: time taken to serve the request
; it can accept the following format:
; - %{seconds}d (default)
; - %{miliseconds}d
; - %{mili}d
; - %{microseconds}d
; - %{micro}d
; %e: an environment variable (same as $_ENV or $_SERVER)
; it must be associated with embraces to specify the name of the env
; variable. Some exemples:
; - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e
; - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e
; %f: script filename
; %l: content-length of the request (for POST request only)
; %m: request method
; %M: peak of memory allocated by PHP
; it can accept the following format:
; - %{bytes}M (default)
; - %{kilobytes}M
; - %{kilo}M
; - %{megabytes}M
; - %{mega}M
; %n: pool name
; %o: output header
; it must be associated with embraces to specify the name of the header:
; - %{Content-Type}o
; - %{X-Powered-By}o
; - %{Transfert-Encoding}o
; - ....
; %p: PID of the child that serviced the request
; %P: PID of the parent of the child that serviced the request
; %q: the query string
; %Q: the '?' character if query string exists
; %r: the request URI (without the query string, see %q and %Q)
; %R: remote IP address
; %s: status (response code)
; %t: server time the request was received
; it can accept a strftime(3) format:
; %d/%b/%Y:%H:%M:%S %z (default)
; %T: time the log has been written (the request has finished)
; it can accept a strftime(3) format:
; %d/%b/%Y:%H:%M:%S %z (default)
; %u: remote user
;slowlog = log/$pool.log.slow 用于记录慢请求
;request_slowlog_timeout = 0 慢日志请求超时时间,对一个php程序进行跟踪。
;request_terminate_timeout = 0 终止请求超时时间,在worker进程被杀掉之后,提供单个请求的超时间隔。由于某种原因不停止脚本执行时,应该使用该选项,0表示关闭不启用
(在php.ini中,max_execution_time 一般设置为30,表示每一个脚本的最大执行时间)
;rlimit_files = 1024 设置打开文件描述符的限制
;rlimit_core = 0 设置内核对资源的使用限制,用于内核转储
;chroot = 设置chroot路径,程序一启动就将其chroot放置到指定的目录下,该指令值必须是一个绝对路径
;chdir = /var/www 在程序启动时将会改变到指定的位置(这个是相对路径,相对当前路径或chroot后的“/”目录)
;catch_workers_output = yes 将worker的标准输出和错误输出重定向到主要的错误日志记录中,如果没有设置,根据FastCGI的指定,将会被重定向到/dev/null上
;clear_env = no 清理环境
;security.limit_extensions = .php .php3 .php4 .php5 限制FPM执行解析的扩展名
;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp ; Additional php.ini defines, specific to this pool of workers. These settings
; overwrite the values previously defined in the php.ini. The directives are the
; same as the PHP SAPI:
; php_value/php_flag - you can set classic ini defines which can
; be overwritten from PHP call 'ini_set'.
; php_admin_value/php_admin_flag - these directives won't be overwritten by
; PHP call 'ini_set'
; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no. ; Defining 'extension' will load the corresponding shared extension from
; extension_dir. Defining 'disable_functions' or 'disable_classes' will not
; overwrite previously defined php.ini values, but will append the new value
; instead. ;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com
;php_flag[display_errors] = off
;php_admin_value[error_log] = /var/log/fpm-php.www.log
;php_admin_flag[log_errors] = on
;php_admin_value[memory_limit] = 32M
总结
1) 在php-fpm的配置文件中,有两个指令非常重要,就是"pm.max_children" 和 "request_terminate_timeout"
第一个指令"pm.max_children" 确定了php-fpm的处理能力,原则上时越多越好,但这个是在内存足够打的前提下,每开启一个php-fpm进程要占用近30M左右的内存
如果请求访问较多,那么可能会出现502,504错误。对于502错误来说,属于繁忙进程而造成的,对于504来说,就是客户发送的请求在限定的时间内没有得到相应,过多的请求导致“504 Gateway Time-out”。这里也有可能是服务器带宽问题。
另外一个需要注意的指令"request_terminate_timeout",它决定php-fpm进程的连接/发送和读取的时间,如果设置过小很容易出现"502 Bad Gateway" 和 “504 Gateway Time-out”,默认为0,就是说没有启用,不加限制,但是这种设置前提是你的php-fpm足够健康,这个需要根据实际情况加以限定。
php-fpm配置文件详解的更多相关文章
- php-fpm.conf 配置文件详解
php-fpm.conf 配置文件详解 [global] pid = run/php-fpm.pid error_log = log/php-fpm.log log_level = notice # ...
- Nginx配置配置文件详解
文章目录 配置文件 nginx.conf配置文件详解 用于调试.定位问题的配置参数 正常运行必备的配置参数 优化性能的配置参数 事件相关配置 Fastcgi相关配置参数 常需要调整的参数 nginx作 ...
- quartz配置文件详解
quartz配置文件详解(转载) quartz学习总结: 一.关于job: 用Quartz的行话讲,作业是一个执行任务的简单Java类.任务可以是任何Java代码.只需你实现org.qu ...
- WebConfig配置文件详解
今天看到博客园一位朋友整理的一个WebConfig配置文件详解,觉得不错,转载一下: <?xml version="1.0"?> <!--注意: 除了手动编辑此文 ...
- tomcat配置文件详解
Tomcat系列之服务器的安装与配置以及各组件详解 tomcat 配置文件详解
- ubuntu nginx 安装以及配置文件详解
1.到nginx官网下载源码包.最好下载稳定版本,nginx官网http://www.nginx.org/ 2.安装nginx依赖包运行命令: sudo apt-get install libssl- ...
- Spring配置文件详解 – applicationContext.xml文件路径
Spring配置文件详解 – applicationContext.xml文件路径 Java编程 spring的配置文件applicationContext.xml的默 ...
- spring配置文件详解--真的蛮详细
spring配置文件详解--真的蛮详细 转自: http://book.51cto.com/art/201004/193743.htm 此处详细的为我们讲解了spring2.5的实现原理,感觉非常 ...
- net-snmp配置文件详解
net-snmp配置文件详解 net-snmp的配置文件是有一定的层次结构的,配置起来也很方便.网上找了很多资料,大概把这个配置文件的各个信息搞懂了一点.其实在net-snmp的EXAMPLE.con ...
- Rsyslog配置文件详解
Rsyslog配置文件详解https://my.oschina.net/0757/blog/198329 # Save boot messages also to boot.log 启动的相关信息lo ...
随机推荐
- [iOS UI进阶 - 2.3] 彩票Demo v1.3
A.需求 真机调试 "关于”模块 存储开关状态 打电话.发短信 应用评分 打开其他应用 cell 在iOS6 和 iOS7的适配 block的循环引用 屏幕适配 code source: ...
- php-fpm 启动不了 libiconv.so.2找不到
service php-fpm start Starting php-fpm /alidata/server/php/sbin/php-fpm: error while loading shared ...
- UVA 11426 GCD - Extreme (II) (欧拉函数+筛法)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70017#problem/O 题意是给你n,求所有gcd(i , j)的和,其中 ...
- Intel® RealSense™ SDK Architecture
In this article, we highlight some of the key changes that you can expect to see in the Intel RealSe ...
- Openfire服务器MySQL优化
Openfire服务器MySQL优化: [root@iZ28g4ctd7tZ ~]# mysql -u root -p XXXXX mysql> show processlist; +----- ...
- 【M20】协助完成“返回值优化(RVO)”
1.方法返回对象,会导致临时对象的产生,这降低了效率,const Rational operator* (const Rational& lhs,Rational& rhs).有没有什 ...
- Codeforces Round #332 (Div. 2) C. Day at the Beach 线段树
C. Day at the Beach Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/599/p ...
- codeforces Gym 100500H H. ICPC Quest 水题
Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...
- STL中heap算法(堆算法)
①push_heap算法 以下是push_heap算法的实现细节.该函数接收两个迭代器,用来表现一个heap底部容器(vector)的头尾,而且新元素已经插入究竟部的最尾端. template ...
- Delphi 7 升级到 Delphi 2010 总结
1 字符串 >>string =unicodeString 字母的处理要定义AnsiString了 >>PChar =PWidechar >>str='普通汉字' ...