參數 | 說明php
-p | 命令行中動態修改--prefix linux
;include=etc/fpm.d/*.conf | 用於包含一個或多個文件,若是glob(3)存在(glob()函數返回匹配指定模式的文件名或目錄)服務器
由標誌[global]開始:app
;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可以處理進程池數目的多少並無限制dom
其中$pool變量能夠在任何指令中使用,他將會替代相應的進程池名字。例如:這裏的[www]socket
[root@test ~]# ps -ef | grep php-fpm root 3028 1 0 20:33 ? 00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf) nobody 3029 3028 0 20:33 ? 00:00:00 php-fpm: pool www nobody 3030 3028 0 20:33 ? 00:00:00 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"ide
第一個指令"pm.max_children" 肯定了php-fpm的處理能力,原則上時越多越好,但這個是在內存足夠打的前提下,每開啓一個php-fpm進程要佔用近30M左右的內存函數
若是請求訪問較多,那麼可能會出現502,504錯誤。對於502錯誤來講,屬於繁忙進程而形成的,對於504來講,就是客戶發送的請求在限定的時間內沒有獲得相應,過多的請求致使「504 Gateway Time-out」。這裏也有多是服務器帶寬問題。php-fpm
另一個須要注意的指令"request_terminate_timeout",它決定php-fpm進程的鏈接/發送和讀取的時間,若是設置太小很容易出現"502 Bad Gateway" 和 「504 Gateway Time-out」,默認爲0,就是說沒有啓用,不加限制,可是這種設置前提是你的php-fpm足夠健康,這個須要根據實際狀況加以限定。this