PHP查询结果10M内存会沾满吗,PHP内存限制

在PHP环境中,尽管php.ini设置内存限制为128M,实际脚本运行时内存分配达到23M后即报错。错误日志显示因内存不足(尝试分配25165856字节)引发致命错误。问题可能涉及PHP配置、系统资源或其他因素。
摘要由CSDN通过智能技术生成

我试图在php脚本中测试内存分配。我在php.ini中将限制设置为128M。在脚本中,ini_get('memory_limit')报告128M为限制。问题是,当我开始分配空间时,我无法超越23M。我可以将内存分配限制在23M以下的任何级别,但不能分配更多内存。只是寻找这个限制在哪里被施加的线索。

这是我的测试脚本...

echo "System imposed memory_limit is set to: " . ini_get('memory_limit') . "
\n";

for ($i=1; $i<1000; $i++) {

$a = loadmem($i);

echo "You have allocated ". $i . "M (". memory_get_usage() . ") memory in this php script" . "
\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

You have allocated 1M (1403632) memory in this php script

You have allocated 2M (2452232) memory in this php script

You have allocated 3M (3500808) memory in this php script

You have allocated 4M (4549384) memory in this php script

You have allocated 5M (5597960) memory in this php script

You have allocated 6M (6646536) memory in this php script

You have allocated 7M (7695112) memory in this php script

You have allocated 8M (8743688) memory in this php script

You have allocated 9M (9792264) memory in this php script

You have allocated 10M (10840848) memory in this php script

You have allocated 11M (11889424) memory in this php script

You have allocated 12M (12938000) memory in this php script

You have allocated 13M (13986576) memory in this php script

You have allocated 14M (15035152) memory in this php script

You have allocated 15M (16083728) memory in this php script

You have allocated 16M (17132304) memory in this php script

You have allocated 17M (18180880) memory in this php script

You have allocated 18M (19229456) memory in this php script

You have allocated 19M (20278032) memory in this php script

You have allocated 20M (21326608) memory in this php script

You have allocated 21M (22375184) memory in this php script

You have allocated 22M (23423760) memory in this php script

You have allocated 23M (24472336) memory in this php script
这里是相关的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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值