Heim  >  Artikel  >  Backend-Entwicklung  >  Fatal error: Out of memory (allocated 262144) (tried to allocate 10267220 bytes)解决方案

Fatal error: Out of memory (allocated 262144) (tried to allocate 10267220 bytes)解决方案

WBOY
WBOYOriginal
2016-06-13 10:12:314120Durchsuche

Fatal error: Out of memory (allocated 262144) (tried to allocate 10267220 bytes)
请问这个怎么办?

我在程序前面加一个代码
ini_set('memory_limit', '50M');

要怎样才能运行起来呢?
用的是虚拟主机,

------解决方案--------------------
这个不能这样设置的吧?或者有限制。最好是php.ini里去改,然后重启apache。
不知道ini_set里修改后,是否立即生效。有点悬。
------解决方案--------------------
你可以写段代码测试下的,,应该是可以的……ini_set没有被禁吧

看看是否报内存超出限制

ini_set('memory_limit', '1M');
for($i=0;$i{
$arr[] = $i;
}
------解决方案--------------------
1048576 bytes = 1024K = 1 M

说明设置有效果

1M只是方便测试
------解决方案--------------------
可以立即生效
echo ini_get('memory_limit');//原值
ini_set('memory_limit', '50M');
echo ini_get('memory_limit');//现值

但问题不在这里
Out of memory (allocated 262144) (tried to allocate 10267220 bytes)
是说你在 262144 字节可用内存中
试图申请 10267220 字节空间
这显然是不能够的

memory_limit 表示的是允许php使用的最大空间,并不是一定有 memory_limit 的内存供你使用

你的情况表示内存碎片太多
重启 web 服务应该可以缓解
如频繁发生,就需要考虑安装内存管理软件,或增加内存条了

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:怎么保护网站不被盗用Nächster Artikel:php自动生成txt解决方法