[root@abc lnmp]# service php-fpm start Starting php-fpm eAccelerator: Could not allocate 67108864 bytes, the maximum size the kernel allows is 33554432 bytes. Lower the amount of memory request or increase the limit in /proc/sys/kernel/shmmax. [04-Dec-2013 19:06:44] NOTICE: PHP message: PHP Warning: [eAccelerator] Can not create shared memory area in Unknown on line 0 [04-Dec-2013 19:06:44] NOTICE: PHP message: PHP Fatal error: Unable to start eAccelerator module in Unknown on line 0 failed
eAccelerator(舊版 PHP 加速器)請求 64 MB 共享記憶體,但 Linux 核心參數 kernel.shmmax(單次共享記憶體段最大值)預設僅 32 MB,導致分配失敗,進而阻塞 PHP-FPM 啟動。
vi /etc/sysctl.conf
在檔案末尾新增:
kernel.shmmax = 134217728
說明:設為 128 MB (134217728 bytes) 即可滿足 64 MB 需求並留有餘裕。若記憶體充裕可設更大(如 256 MB = 268435456)。
sysctl -p
cat /proc/sys/kernel/shmmax # 應輸出 134217728
service php-fpm start # Starting php-fpm done
| 參數 | 含義 | 建議值 |
|---|---|---|
kernel.shmmax | 單個共享記憶體段最大位元組數 | 134217728 (128 MB) |
kernel.shmall | 系統共享記憶體總頁數(頁大小通常 4KB) | shmmax / 4096 * 2 |
kernel.shmmni | 系統共享記憶體段最大數量 | 4096 |
若同時運行多個需大量共享記憶體的服務(Redis、PostgreSQL、多 PHP-FPM pool),請同步調大 shmall 與 shmmni。
eAccelerator 已停止維護(最後更新 2012 年)。PHP 5.5+ 內建 Zend OPcache,效能更優、配置更簡單、無共享記憶體段限制問題。強烈建議:
zend_extension=opcache.so + opcache.enable=1<?php
// 檢查 OPcache 狀態
if (extension_loaded('Zend OPcache')) {
echo "OPcache 已載入\n";
print_r(opcache_get_status());
} else {
echo "OPcache 未啟用\n";
}
?>