在LNMP(Linux, Nginx, MySQL, PHP-FPM)环境中优化PHP-FPM可以显著提高应用程序的性能和响应速度。以下是一些常见的优化策略:
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests_per_child = 500
memory_limit = 128M
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
max_execution_time = 30
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
fastcgi_buffer_size = 128k;
fastcgi_buffers = 4 256k;
fastcgi_busy_buffers_size = 256k;
slowlog = /var/log/php-fpm/www-slow.log
request_slowlog_timeout = 10s
log_level = notice
定期重启PHP-FPM可以释放内存并解决一些潜在的问题。
sudo systemctl restart php7.4-fpm
通过这些优化策略,你可以显著提高LNMP环境中PHP-FPM的性能。根据具体的应用程序和环境,可能需要进一步调整这些设置。