php-fpm优化
1.通常情况我们修改/etc/php.ini文件,仅会修改错误日志与文件上传
expose_php = Off
display_error = Off
error_reporting = E_WARNING & E_ERROR
log_errors = On
error_log = /var/log/php_error.log
date.timezone = PRC
file_uploads = On
upload_max_filesize = 300M
post_max_size = 300M
max_file_uploads = 20
memory_limit = 128M
sql.safe_mode = Off
post_max_size = 300M
upload_max_filesize = 300M
max_file_uploads = 20
memory_limit = 128M
date.timezone = Asia/Shanghai
expose_php = Off
display_error = Off
error_reporting = E_WARNING & E_ERROR
log_errors = On
error_log = /var/log/php_error.log
2. php-fpm主配置文件/etc/php-fpm.conf调整
;include=etc/fpm.d/*.conf
[global]
;pid = /var/log/php-fpm/php-fpm.pid
;error_log = /var/log/php-fpm/php-fpm.log
;log_level = error
rlimit_files = 65535
events.mechanism = epoll
[www]
user = www
group = www
;listen = /dev/shm/php-fpm.sock
listen = 127.0.0.1:9000
;listen.allowed_clients = 127.0.0.1
; Choose how the process manager will control the number of child processes.
; Possible Values:
; static - a fixed number (pm.max_children) of child processes;
; dynamic - the number of child processes are set dynamically based on the
; following directives:
; pm.max_children - the maximum number of children that can
; be alive at the same time.
; pm.start_servers - the number of children created on startup.
; pm.min_spare_servers - the minimum number of children in 'idle'
; state (waiting to process). If the number
; of 'idle' processes is less than this
; number then some children will be created.
; pm.max_spare_servers - the maximum number of children in 'idle'
; state (waiting to process). If the number
; of 'idle' processes is greater than this
; number then some children will be killed.
; Note: This value is mandatory.
pm = dynamic
pm.max_children = 512
pm.start_servers = 32
pm.min_spare_servers = 32
pm.max_spare_servers = 64
pm.max_requests = 1500
pm.process_idle_timeout = 15s;
php_flag[display_errors] = off
php_admin_value[error_log] = /soft/log/php/php-www_error.log
php_admin_flag[log_errors] = on
request_slowlog_timeout = 5s
slowlog = /var/log/php/slow.log
3. php-fpm状态模块,用于监控php-fpm状态使用
[root@nginx ~]
pm.status_path = /phpfpm_status
[root@nginx conf.d]
server {
listen 80;
server_name php.qls.com;
location / {
root /code;
index index.php;
}
location /phpfpm_status {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
4. 访问测试phpfpm_status状态页面
[root@nginx ~]
pool: www
process manager: dynamic
start time: 05/Jul/2016:15:30:56 +0800
start since: 409
accepted conn: 22
listen queue: 0
max listen queue: 0
listen queue len: 128
idle processes: 4
active processes: 1
total processes: 5
max active processes: 2
max children reached: 0
pool
process manager
start time
start since
accepted conn
listen queue
max listen queue
listen queue len
idle processes
active processes
total processes
max active processes
max children reached
5. PHP-FPM配置文件
[root@nginx ~]
[global]
pid = /var/run/php-fpm.pid
error_log = /var/log/php/php-fpm.log
log_level = warning
rlimit_files = 655350
events.mechanism = epoll
[www]
user = nginx
group = nginx
listen = 127.0.0.1:9000
listen.owner = www
listen.group = www
listen.mode = 0660
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 512
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 30
pm.process_idle_timeout = 15s;
pm.max_requests = 2048
pm.status_path = /phpfpm_status
php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/php/php-www.log
php_admin_flag[log_errors] = on
request_slowlog_timeout = 5s
slowlog = /var/log/php/php-slow.log
