提升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
)優化內存管理。注意:修改配置前需備份文件,建議在測試環境驗證后再應用到生產環境。