drqefnd544707688 2016-02-17 10:03
浏览 425
已采纳

PHP:内存不足异常,但我已经更改了memory_limit

I was getting this error:

PHP Fatal error: Allowed memory size of X bytes exhausted

So, after some research I changed my php.ini file:

memory_limit: 2048M

The previous error message stoped but I get this error instead:

Fatal error: Out of memory (allocated 1746927616) (tried to allocate 268435456 bytes) in [path]

So I've got 2048M as memory limit and in my error the php file allocated 1666M and tried to allocate 256M which give 1922M. This value is smaller than my memory limit so why I am getting this error? (I've checked the php info in my IIS site and the memory limit is the one I mention before).

Thanks :)

EDIT:

Right before the line in which this error ocorred I did a

echo memory_get_usage();

And I got:

1675848

The code where's the error is this:

for ($i = $startKey; $i <= $endKey; $i++) {
        array_push($paginas, $files[$i]);
}
  • 写回答

2条回答 默认 最新

  • dsavz66262 2016-02-17 11:05
    关注

    Well thank you for your tips. It's actually a code-design problem. This isn't my code (I've started working in a already existing project) so it's been a little harder do debug and to decide if I look for some configuration error or assume the code is bad. When I first searched the error I found so many people with the same problem that I stupidly rulled out bad code (and the error was hapening in a part that deals with files).

    So, in my case and as suggested here, I start looking my code and used the

    echo memory_get_usage();
    

    To see if all the memory was really been allocated in that line of code and find out that was true. So then I checked the loop variables and sometimes the first one wasn't initalized corretly and the consequence was a no-ending loop.

    Thank you all and sorry for the trouble :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来