我的知识记录

打开网站显示Fatal error_ Allowed memory size of X bytes exhausted (tried to allocate Y bytes)错误怎么办_已解决

Fatal error: Allowed memory size of X bytes exhausted (tried to allocate Y bytes) in /path/to/file.php on line X

 
问题:PHP 提示允许的内存大小不足,超出限制
 
原因:处理大文件 / 大数据集(如读取大 CSV、循环创建大数组)、递归调用无终止条件导致内存泄漏、php.ini 中 memory_limit 配置过小
 
解决方案:
1. 临时调整内存限制:ini_set('memory_limit', '256M');(或设为 -1 无限制,不建议生产环境);
2. 优化代码:分批处理大数据、终止递归死循环、及时释放变量(unset($bigArr););
3. 永久修改 php.ini:memory_limit = 256M,重启 PHP-FPM/Apache

打开网站显示Fatal error_ Allowed memory size of X bytes exhausted (tried to allocate Y bytes)错误怎么办_已解决

标签:

更新时间:2026-03-12 11:07:20

上一篇:网站出现 500 错误,大概率是服务器自身问题(如服务器过载、程序报错、数据库异常)

下一篇:网站安装报错“SQLSTATE(HY000)_ General error_ 1615 Prepared statement needs to be re-prepared”问题_已解决