Optimization of PHP-FPM parameters under high concurrency and high load
Optimization of PHP-FPM parameters under high concurrency and high load
Mainly for parameter tuning of PHP in Linux
Adjust file descriptor limits
# Ulimit-n 1000000
# Vi/etc/security/limits. conf
# Setting Shell Limits for File Descriptors
* Soft nofile 1000000
* Hard nofile 1000000
Disable the file system access time update in the partition where the PHP code file is located
# Vi/etc/fstab
For example, the partition where the PHP code is located:
/Dev/sdb1 ext4 errors = remount-ro 0 1
To:
/Dev/sdb1 ext4 noatime, nodiratime, errors = remount-ro 0 1
Store temporary files to tmpfs
(Note) when a website needs to process a large number of small image uploads, it uses the memory file system tmpfs for storage, which can reduce the I/O overhead. however, if you upload a very large file (such as a video), tmpfs is not suitable.
# Vi/etc/fstab
Tmpfs/tmp tmpfs defaults, nosuid, noatime 0 0
Php. ini configuration optimization
# Vi php-app.ini
[PHP]
Engine = On
Expose_php = Off
Max_execution_time = 5
Memory_limit = 256 M
Error_reporting = E_ALL &~ E_DEPRECATED
Display_errors = Off
Display_startup_errors = Off
Html_errors = Off
Default_socket_timeout = 5
File_uploads = On
Upload_tmp_dir =/tmp/php
Upload_max_filesize = 50 M
Post_max_size = 50 M
Max_file_uploads = 20
Date. timezone = 'Asia/Shanghai'
Note that max_execution_time is set to only 5 seconds. for a fast web application, we really don't want any web requests that run for a long time in the web application. a web request lasts for more than five seconds, which usually means something goes wrong. our goal is that the page response should be within-Ms.
PHP-FPM configuration tuning
# Vi php-fpm.conf
[My_app]
; FastCGI/PHP-FPM using UNIX Sockets
Listen =/data/my_app/tmp/php. sock
Listen. backlog = 300.
User = www
Group = www
Pm = dynamic
; Estimate pm. max_children = (MAX_MEMORY-500 MB)/20 MB
Pm. max_children = 100
; Recommended as % 10 of the maximum pm. max_children
Pm. start_servers = 10
Pm. min_spare_servers = 5
Pm. max_spare_servers = 15
Pm. max_requests = 1000
Pm. status_path =/php_status
Request_terminate_timeout = 0
Request_slowlog_timeout = 0
Slowlog =/data/my_app/logs/slow. log
The above is a summary of these parameters.