Contract several directories/usr/local/php/sbin/php-FPM/usr/local/php/etc/php-fpm.conf/usr/local/php/etc/php.ini One, PHP-fpm Startup Parameters # Test PHP-FPM Configuration/USR/LOCAL/PHP/SBIN/PHP-FPM-T/usr/local/php/sbin/php-fpm-c/usr/local/php/etc/php.ini-y/usr/local/php/etc/php-fpm.conf-T #启动php-FPM/usr/local/php/sbin/php-FPM/usr/local/php/sbin/php-fpm-c/usr/local/php/etc/php.ini-y/usr/local/php/etc/php-fpm.conf #关闭php-Fpmkill-int ' cat/usr/local/php/var/run/php-fpm.pid ' #重启php-Fpmkill-USR2 ' cat/usr/local/php/var/run/php-fpm.pid ' Two, PHP-fpm.conf Important parameter detailed PID= run/php-fpm.pid#pid settings, default in the installation directory of Var/run/php-Fpm.pid, it is recommended to open Error_log= log/php-fpm.log# error log, default in the installation directory of Var/log/php-Fpm.log Log_level=notice# error level. The available levels are: alert (must be processed immediately), error (Error condition), warning (warning condition), notice (general important information), debug (debug Info). Default: Notice. emergency_ Restart_threshold= -Emergency_restart_interval=60s# means PHP with SIGSEGV or sigbus errors within the values set by Emergency_restart_interval-cgi number of processes if more than Emergency_restart_threshold, php-The FPM will be gracefully restarted. These two options generally leave the default values. Process_control_timeout=0#设置子进程接受主进程复用信号的超时时间. Available units: s (seconds), M (min), H (Hours), or D (days) default units: s (seconds). Default:0. Daemonize=The yes# background performs FPM, the default is yes, and if for debugging you can change to No. In FPM, 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监听端口, the address that PHP handles in Nginx, the general default value can be. Available formats are:'Ip:port','Port','/path/to/unix/socket'. Each process pool needs to be set. Listen.backlog= -1#backlog数,1 means no limit and is determined by the operating system, and this line is commented out. Backlog meaning reference: http://www.3gyou.cc/?p=41listen.allowed_clients=127.0.0.1#允许访问FastCGI进程的IP, set any to No limit IP, if you want to set other hosts Nginx can also access this FPM process, listen to set the cost of access to the IP. The default value is any. Each address is separated by commas. Allows any server to request a connection if it is not set or is empty Listen.owner=Wwwlisten.group=Wwwlisten.mode=0666#unix Socket Settings option, if accessed using TCP, Comment here. User=Wwwgroup=www# Start the process account and group PM=Dynamic#对于专用服务器, the PM can be set to static. #如何控制子进程, the options are static and dynamic. If Static is selected, the number of fixed child processes is specified by Pm.max_children. If dynamic is selected, it is determined by the following argument: Pm.max_children #, maximum number of child processes Pm.start_servers #, number of processes at startup Pm.min_spare_servers #, minimum number of idle processes guaranteed, If the idle process is less than this value, a new child process Pm.max_spare_servers # is created, guaranteeing the maximum number of idle processes, which is cleaned up if the idle process is larger than this value pm.max_requests= +#设置每个子进程重生之前服务的请求数. It is useful for third-party modules that may have a memory leak. If set to'0'The request is always accepted. Equivalent to the PHP_FCGI_MAX_REQUESTS environment variable. Default value:0. Pm.status_path= /the URL of the STATUS#FPM status page. If there is no setting, the status page cannot be accessed. Default value: None. Munin monitoring will be used to Ping.path= /ping#fpm the ping URL of the monitoring page. If not set, the ping page cannot be accessed. This page is used to externally detect whether FPM is alive and can respond to requests. Note that you must start with a slash (/). Ping.response=The pong# is used to define the return of the ping request accordingly. Return as HTTP $The text/Plain formatted text. Default value: Pong. Request_terminate_timeout=0#设置单个请求的超时中止时间. This option may be in the php.ini settings'Max_execution_time'Scripts that are not aborted for some special reasons are useful. Set to'0'Said'Off'You can try changing this option when a 502 error occurs frequently. Request_slowlog_timeout=10s# When a time-out is requested for this setting, the corresponding PHP call stack information is written to the slow log. Set to'0'Said'Off'Slowlog= log/$pool. log.slow# Slow-Request logging, with request_slowlog_timeout use Rlimit_files=1024x768#设置文件打开描述符的rlimit限制. Default value: System-defined value the default open handle is 1024, you can use Ulimit-N View, Ulimit-N 2048 modification. Rlimit_core=0#设置核心rlimit最大限制值. Available values:'Unlimited', 0, or a positive integer. Default value: System-defined value. chroot=#启动时的Chroot目录. The defined directory needs to be an absolute path. If not set, Chroot is not used. ChDir=#设置启动目录, the directory is automatically chdir on startup. The directory you define needs to be an absolute path. Default value: Current directory, or/directory (chroot) Catch_workers_output=yes# redirects the stdout and stderr to the primary error log file during the run. If there are no settings, stdout and stderr will be redirected to the following fastcgi rules./dev/NULL. Default value: null. Three, common errors and Solutions collation1, request_terminate_timeout The resource problem caused by the Request_terminate_timeout value if set to 0 or too long can cause file_get_contents resource problems. If the remote resource requested by file_get_contents is too slow, file_get_contents will remain stuck there and will not time out. We know that php.ini inside Max_execution_time can set the maximum execution time for PHP scripts, but in PHP-cgi (PHP-FPM), this parameter is not effective. The real ability to control the maximum execution time for PHP scripts is php-the Request_terminate_timeout parameter in the fpm.conf configuration file. Request_terminate_timeout Default value is0seconds, meaning that the PHP script will continue to execute. This way, when all the php-cgi processes are stuck in the file_get_contents () function, the nginx+php WebServer can no longer process the new PHP request, and Nginx will return the user "502Bad Gateway. " To modify this parameter, it is necessary to set the maximum execution time for a PHP script, but the symptom is not a cure. For example, to 30s, if file_get_contents () gets a slower page content, this means MaxA php-cgi process, which can only be processed per second5Request, WebServer is also very difficult to avoid "502Bad Gateway. " The workaround is to set the request_terminate_timeout to 10s or a reasonable value, or to add a timeout parameter to file_get_contents. $ctx=stream_context_create (Array ('http'=Array ('Timeout'=Ten //set a time-out in seconds ))); File_get_contents ($str,0, $ctx);2, the max_requests parameter is improperly configured and may cause an intermittent 502 error: Pm.max_requests= +sets the number of requests for the service before each child process is reborn. It is useful for third-party modules that may have a memory leak. If set to '0The request has been accepted. Equivalent to the PHP_FCGI_MAX_REQUESTS environment variable. Default value:0This section of the configuration means that when a PHPThe number of requests processed by the-CGI process accumulates to -automatically restarts the process. But why restart the process? Generally in the project, we will more or less use some PHP third-party libraries, these third-party libraries often have a memory leak problem, if you do not periodically restart PHP-CGI process, it is bound to cause memory usage is increasing. So php-fpm, as the manager of PHP-CGI, provides such a monitoring function for a specified number of requests php-The CGI process restarts to ensure that the amount of memory is not increased. Precisely because of this mechanism, in high-concurrency sites, often leads to502Error, I guess the reason is that the PHP-FPM has not handled the request queue coming from NGINX. But I'm still using PHP for the moment.5.3.2, do not know in PHP5.3.3whether this problem still exists in the Our solution now is to set this value as large as possible, minimizing PHP-cgi re-SPAWN the number of times, while also improving overall performance. In our own actual production environment we found that the memory leaks were not obvious, so we set this value to very large (204800). We must set this value according to their actual situation, can not blindly increase. In other words, the purpose of this mechanism is only to ensure that PHP-CGI does not take up too much memory, so why not handle it by detecting memory? I very much agree with Gao Chunhui that by setting the peak intrinsic consumption of the process to restart php-The CGI process will be a better solution. 3, php-fpm Slow log, Debug and exception troubleshooting artifact: Request_slowlog_timeout set a timeout parameter, Slowlog set the location of the slow log tail-F/var/log/www.slow.log The above command to see the slow-running PHP process. You can see the frequent occurrence of network read more than, MySQL query too slow problem, according to the prompt information to troubleshoot the problem there is a clear direction.
FPM Configuration Detailed