首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 網頁程式設計 >> PHP 程式設計 >> PHP 綜合知識

PHP-FPM 啟動報錯「eAccelerator 共享記憶體不足」完整解決方案

     編輯:PHP 綜合知識

錯誤現場

[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 啟動。

解決步驟

1. 修改 sysctl 配置

vi /etc/sysctl.conf

在檔案末尾新增:

kernel.shmmax = 134217728

說明:設為 128 MB (134217728 bytes) 即可滿足 64 MB 需求並留有餘裕。若記憶體充裕可設更大(如 256 MB = 268435456)。

2. 立即生效

sysctl -p

3. 驗證參數

cat /proc/sys/kernel/shmmax
# 應輸出 134217728

4. 重啟 PHP-FPM

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,效能更優、配置更簡單、無共享記憶體段限制問題。強烈建議:

  • 升級 PHP 至 7.4 / 8.1+
  • 啟用 OPcache:zend_extension=opcache.so + opcache.enable=1
  • 移除 eAccelerator 相關配置

快速驗證腳本

<?php
// 檢查 OPcache 狀態
if (extension_loaded('Zend OPcache')) {
    echo "OPcache 已載入\n";
    print_r(opcache_get_status());
} else {
    echo "OPcache 未啟用\n";
}
?>
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved