提升CentOS下PHP性能可从以下方面入手:
sudo yum install php-opcache
# 编辑/etc/php.ini,添加:
[opcache]
zend_extension=opcache.so
opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=4000
pm.max_children
、pm.start_servers
等),匹配服务器资源,避免进程过多或过少。# 编辑/etc/php-fpm.d/www.conf
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
memory_limit
(如256M),避免脚本因内存不足中断。disable_functions
),减少安全风险。vm.swappiness
)优化内存管理。注意:修改配置前需备份文件,建议在测试环境验证后再应用到生产环境。