我有一个PHP应用程序,它需要大量内存。我将memory_limit
设置为-1在php.ini中。不幸的是,我仍然了解到这个问题:
致命错误:内存不足(分配870318080) (尝试分配138412032字节)
此时,我的系统有超过4GB的空闲内存(我已经安装了12 GB )。所以这不是硬件限制。
我还试图在代码中设置它:
<?php
ini_set('memory_limit','-1');
?>
我所做的也是将其设置为2048M,但错误仍然存在。它总是在1GB左右,所以有任何硬编码的1GB限制吗?
我的系统是什么样子:
更新:
下面是复制它的脚本:
<?php
ini_set("memory_limit", -1);
echo formatSizeUnits(memory_get_usage()).PHP_EOL;
for($i=0;$i<=10; $i++) {
$content[$i] = file_get_contents("http://mirror.softaculous.com/apache/lucene/solr/6.0.0/solr-6.0.0.zip");
echo formatSizeUnits(memory_get_usage()).PHP_EOL;
}
function formatSizeUnits($bytes)
{
if ($bytes >= 1073741824)
{
$bytes = number_format($bytes / 1073741824, 2) . ' GB';
}
elseif ($bytes >= 1048576)
{
$bytes = number_format($bytes / 1048576, 2) . ' MB';
}
elseif ($bytes >= 1024)
{
$bytes = number_format($bytes / 1024, 2) . ' KB';
}
elseif ($bytes > 1)
{
$bytes = $bytes . ' bytes';
}
elseif ($bytes == 1)
{
$bytes = $bytes . ' byte';
}
else
{
$bytes = '0 bytes';
}
return $bytes;
}
?>
我的产出:
php test.php
123.37 KB
164.25 MB
328.37 MB
492.49 MB
PHP Fatal error: Out of memory (allocated 688914432) (tried to allocate 171966464 bytes) in test.php on line 12
Fatal error: Out of memory (allocated 688914432) (tried to allocate 171966464 bytes) in test.php on line 12
更新2:
我安装了一个x64 PHP5.6.20。现在我可以克服这个限制了。这是x86 PHP的官方限制吗?
发布于 2016-04-20 14:16:03
我相信32位进程所能处理的理论极限是3GB (当然有窍门),但是PHP在崩溃之前很难达到1GB,至少在我的经验中是这样的。
您至少应该尝试优化您的代码,因为首先您要在内存中加载一组ZIP档案,而且可能没有很好的理由。
https://stackoverflow.com/questions/36744410
复制相似问题