How do you debug php “Out of Memory” issues?

前端 未结 6 828
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-09 02:46

I\'ve had some issues lately with PHP memory limits lately:

Out of memory (allocated 22544384) (tried to allocate 232 bytes)

<
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-09 03:15

    I wonder is perhaps your thinking regards methodology is flawed here.

    The basic answer to your question - how do I find out where this error is occurring? - has already been answered; you know what's causing that.

    However, this is one of those cases where the triggering error isn't really the problem - certainly, that 232 byte object isn't your problem at all. It is the 20+Megs that was allocated before it.

    There have been some ideas posted which can help you track that down; you really need to look "higher level" here, at the application architecture, and not just at individual functions.

    It may be that your application requires more memory to do what it does, with the user load you have. Or it may be that there are some real memory hogs that are unnecessary - but you have to know what is necessary or not to answer that question.

    That basically means going line-by-line, object-by-object, profiling as needed, until you find what you seek; big memory users. Note that there might not be one or two big items... if only it were so easy! Once you find the memory-hogs, you then have to figure out if they can be optimized. If not, then you need more memory.

提交回复
热议问题