9

报错 Allowed memory size of 134217728 bytes exhausted 解决方法

 2 years ago
source link: https://opssh.cn/daima/211.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

报错 Allowed memory size of 134217728 bytes exhausted 解决方法

日期:2022年04月11日
·
分类:技术积累
已阅读 80 次

刚给李洋个人博客修改小程序前端发现某个分类的 api接口 报错 Allowed memory size of 134217728 bytes exhausted,详细错误如下,可以从报错中确认的是允许的内存大小已用尽,解决起来也就方便很多,如出现以下情况如何解决呢?

{code:500,message:“System error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 52074865 bytes)”}

报错 Allowed memory size of 134217728 bytes exhausted 解决方法

问题分析

首先要了解的是 php 的 api 接口是如何处理的,每当我们请求 api 接口数据,都要通过内存处理,如果内存太小、数据量过大,那么就会导致脚本内存溢出不够用的情况,导致内存溢出不够用的原因可能有三种,如下:

1、查询或请求数据量大

2、php.ini 配置文件限制内存

3、文章内图片体积巨大,超过 memory_limit 限制

解决方法

因 php 默认内存限制是 128M,需要修改 php.ini 配置文件,在 php.ini 配置文件 找到 memory_limit = 128M ,将默认的 128M 修改为合适的数值,如:等于或小于 1G 内存修改为 256M 或 512M,等于大于 2G 内存,可以修改高于 1024M。

# 小于等于 1G 内存
memory_limit = 512M
# 大于等于 2G 内存
memory_limit = 1024M

如不知 php.ini 配置文件存放在服务器什么位置,可以使用以下命令来查找,命令如下:

php -i | grep php.ini

如果你是宝塔用户,可在“PHP 版本管理”内找到“配置修改”,将“memory_limit”修改为大于“128M”,如下图:

宝塔修改memory_limit内存限制

修改完成后重启 Linux 服务器,命令如下:

shutdown -r now

最后总结

如你是 128M 或 256M 小内存服务器,那么就控制 图片输出数量 和 数据数量,图片没办法避免,那么就进行压缩图片,将图片体积尽量压缩的最小。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK