我试图在php脚本中测试内存分配。我在php.ini中将限制设置为128M。在脚本中,ini_get(' memory_limit')报告128M作为限制。问题是,当我开始分配空间时,我不能超过23M。我可以将内存分配限制在23M以下的任何级别,但不能分配更多。只是寻找关于这个限制在何处施加的线索。
这是我的测试脚本......
<?php
echo "System imposed memory_limit is set to: " . ini_get('memory_limit') . "<br>\n";
for ($i=1; $i<1000; $i++) {
$a = loadmem($i);
echo "You have allocated ". $i . "M (". memory_get_usage() . ") memory in this php script" . "<br />\n";
unset($a);
}
function loadmem($howmuchmeg) {
$a = str_repeat("0", $howmuchmeg * 1024 * 1024); // alocating 10 chars times million chars
return $a;
}
?>
这里是使用curl的输出...
System imposed memory_limit is set to: 128M<br>
You have allocated 1M (1403632) memory in this php script<br />
You have allocated 2M (2452232) memory in this php script<br />
You have allocated 3M (3500808) memory in this php script<br />
You have allocated 4M (4549384) memory in this php script<br />
You have allocated 5M (5597960) memory in this php script<br />
You have allocated 6M (6646536) memory in this php script<br />
You have allocated 7M (7695112) memory in this php script<br />
You have allocated 8M (8743688) memory in this php script<br />
You have allocated 9M (9792264) memory in this php script<br />
You have allocated 10M (10840848) memory in this php script<br />
You have allocated 11M (11889424) memory in this php script<br />
You have allocated 12M (12938000) memory in this php script<br />
You have allocated 13M (13986576) memory in this php script<br />
You have allocated 14M (15035152) memory in this php script<br />
You have allocated 15M (16083728) memory in this php script<br />
You have allocated 16M (17132304) memory in this php script<br />
You have allocated 17M (18180880) memory in this php script<br />
You have allocated 18M (19229456) memory in this php script<br />
You have allocated 19M (20278032) memory in this php script<br />
You have allocated 20M (21326608) memory in this php script<br />
You have allocated 21M (22375184) memory in this php script<br />
You have allocated 22M (23423760) memory in this php script<br />
You have allocated 23M (24472336) memory in this php script<br />
以下是相关的error_log条目...
mmap() failed: [12] Cannot allocate memory
PHP Fatal error: Out of memory (allocated 2097152) (tried to allocate 25165856 bytes)
使用php 7.0.x和apache2.2
答案 0 :(得分:4)
错误表明您实际上没有那么多内存可用。如果您只是超出了限制,那么您会得到一个略有不同的消息:
PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried...
您的问题可能是实际可用内存或shell强加的ulimit造成的。
答案 1 :(得分:0)
添加这个你的PHP脚本
UTC msg='c:\program files\test\test.dll' was created by 'NT AUTHORITY\SYSTEM'.