Www.linuxidc.comLinux2011-0535346.htm ----------------------- open php-fpm slow script log request_slowlog_timeout30sslowlogusrlocalphpvarlogphp-fpm.log.slow typical log Content: [15-Apr-201220: 56: 19] [poolwww] pid9748s
Http://www.linuxidc.com/Linux/2011-05/35346.htm ----------------------- enable php-fpm slow script log request_slowlog_timeout = 30 s slowlog =/usr/local/php/var/log/php-fpm.log.slow typical log content is as follows: [15-Apr-2012 20:56:19] [pool www] pid 9748 s
Http://www.linuxidc.com/Linux/2011-05/35346.htm
-----------------------Enable php-fpm slow script log
Request_slowlog_timeout = 30 s
Slowlog =/usr/local/php/var/log/php-fpm.log.slow
The typical log content is as follows:
[15-Apr-2012 20:56:19] [pool www] pid 9748
Script_filename =/var/www/html/htdocs/www.xxx.com/xxx.php
[0x00000000090bc270] file_get_contents ()/var/www/html/htdocs/www.xxx.com/xxx.php:81
The slow script file, the specific number of lines, and functions are all detailed records, making optimization easier.
Request_terminate_timeout = 120
# It indicates that after 120 seconds, php scripts that are not automatically ended are ended to release the occupied resources.
When PHP runs in php-fpm mode, the max_execute_time configured by php. ini is invalid and you need to configure another configuration item in the php-fpm.conf: request_terminate_timeout; The following is the description of the official documentation:
Request_terminate_timeout-The timeout (in seconds) for serving a single request after which the worker process will be terminated. shocould be used when 'max _ execution_time 'ini option does not stop script execution for some reason. default: "5s ". note: '0s' means 'off'
Note: set_time_limit () and max_execution_time only affect the script execution time. The maximum execution time of any script that occurs in a system call, stream operation, or database operation that uses system () is not included.
[Global]
Pid =/dev/shm/pid/php-fpm.pid
Error_log =/usr/local/php/var/log/php-fpm.log
Log_level = notice
[Www]
Listen = 127.0.0.1: 9000
; Listen. allowed_clients = 192.168.1.17, 127.0.0.1, 192.168.1.75
User = www
Group = www
Pm = dynamic
Pm. max_children = 2000
Pm. start_servers = 10
Pm. min_spare_servers = 5
Pm. max_spare_servers = 200
Pm. max_requests = 12000
Pm. process_idle_timeout = 10 s
Request_terminate_timeout = 120
Request_slowlog_timeout = 30 s
Slowlog =/usr/local/php/var/log/php-fpm.log.slow
The following parameters are involved: pm, pm. max_children, pm. start_servers, pm. min_spare_servers, and pm. max_spare_servers.
Pm indicates the method used. You can select either static or dynamic values ). In older versions, dynamic is called apache-like. Note the configuration file description.
The meanings of the following four parameters are:
Pm. max_children: Number of php-fpm processes enabled in static mode.
Pm. start_servers: number of initial php-fpm processes in dynamic mode.
Pm. min_spare_servers: the minimum number of php-fpm processes in dynamic mode.
Pm. max_spare_servers: Maximum number of php-fpm processes in dynamic mode.
If dm is set to static, only the pm. max_children parameter takes effect. The system will enable the set number of php-fpm processes.
If dm is set to dynamic, the pm. max_children parameter is invalid and the following three parameters take effect.
The system starts the pm. start_servers php-fpm processes at the beginning of the php-fpm operation,
Then, adjust the number of php-fpm processes between pm. min_spare_servers and pm. max_spare_servers according to system requirements.
Which execution method is better for our servers? In fact, Like Apache, the running PHP program may have more or less memory leakage after execution.
This is why a php-fpm process only occupies about 3 m of memory at the beginning, and will rise to 20-30 m after running for a period of time.
For servers with a large memory (such as 8 GB or above), it is more appropriate to specify the static max_children, because no additional process count control is required and the efficiency is improved.
Because frequent switching of the php-fpm process also has a time delay, enabling static mode will be better if the memory is large enough. The quantity can also be obtained based on the memory/30 M, for example, 8 GB memory can be set to 100,
The memory used by the php-fpm can be controlled at 2G-3G. If the memory is slightly smaller, such as 1 GB, the specified number of static processes is more conducive to server stability.
In this way, php-fpm can only obtain enough memory and allocate a small amount of memory to other applications, making the system run more smoothly.
For servers with small memory, for example, VPS with M memory, even if a 20 M memory is used, 10 php-cgi processes will consume m of memory, the collapse of the system should be normal.
Therefore, we should try our best to control the number of php-fpm processes, and specify a small static number for other applications after specifying the memory occupied by other applications, which will make the system more stable. Or use a dynamic method,
Because the excessive process is terminated dynamically and some memory can be recycled and released, we recommend that you use it on servers or VPS with less memory. The maximum number is calculated based on memory/20 mb.
For example, we recommend that you set pm. max_spare_servers to 20 for m vps. For pm. min_spare_servers, we recommend that you set the value based on the server load. The value range is 5 ~ Between 10.
============================== 127.0.0.1 listens to the local ip Address
Php-fpm.conf
Listen = 127.0.0.1: 9000
Nginx. conf
Location ~ ^ (. + \. Php) (. *) $ {
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fcinclude gi. conf;
}