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条)

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集