How to Debug “Fatal error: Out of memory (allocated XXX) (tried to allocate XXXXX bytes)”? [closed]

此生再无相见时 提交于 2019-12-10 10:53:53

问题


Looking through StackOverflow I realized out-of-memory-errors are a common problem. As suggested by others it can under some circumstances be managed by increasing the memory limit in the php.ini.But often this doesn't solve the error as there is a problem within the coding.

What are most common sources of this error? How do you design your code to avoid it? How do you approach debugging such an error?

So far I know as sources:

  • indefinite loops
  • fetching large amount of db-data into a variable (possibly it helps to unset vars after using them, if it's more than one?)

回答1:


Yes, of course.

You have to get your /xxxxx/xxxxx.xxx script and sort things out related to the operation performed on the line 22.
And make it less memory consuming.




回答2:


There are 2 solutions

If

  • your website has a lot of traffic
  • your server is used to do some memory-intensive stuff (generating PDF/image, etc.)

Then it's normal for the server to run out of memory if there simply is too much people simultaneously on your website. The only solution is to increase it. For a website that count a lot of visitor per day, 550M is between low and average amount.

But if your website has only few traffic, like a small company website, then you might have a problem. Check what processes are eating the memory - using topor htop for example - and act accordingly.

If it's PHP that is consumming too much RAM, usually this kind of error is caused by an infinite loop, or a long one, like extracting a lot of data from the DB, creating object with each of these records, without freeing memory.



来源:https://stackoverflow.com/questions/8309007/how-to-debug-fatal-error-out-of-memory-allocated-xxx-tried-to-allocate-xxxx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!