Fatal error: Out of memory, but I do have plenty of memory (PHP)

前端 未结 20 2555
情歌与酒
情歌与酒 2020-11-29 23:34

Since my question is getting longer and longer, I decide to re-write the whole question to make it better and shorter.

I run my website on dedicated server with 8GB

相关标签:
20条回答
  • 2020-11-30 00:16

    Could be an issue with MySQL and the number of open connections, hence why it sorts itself out when you restart every few days. Are they auto closing on script shutdown?

    0 讨论(0)
  • 2020-11-30 00:16

    Most of the time you get such a error, problem is in code. I am not trying to say that you are writing code that is bad, I am trying to say that you need to carefully observe what's there in that is using this much amount of memory.

    Always remember "Garbage collection in PHP is pretty bad", it's not like Java, any other such language. there is a way to enforce garbage collection through gc_collect_cycle, but, in my personal opinion, that won't solve your problem. PHP free all memory used for executing a page, once request-response cycle is complete, so you may run into memory issues, if your script is long running, like a background script(Gearman etc), because, memory isn't freed till script is running.

    If above is not the case with your scr,pt, and as you said there is no code that requires such a huge amount of memory, then problem is most definitely in code it self, and upgrading to any version of PHP won't solve the problem. I was facing with one of my Gearman scripts once, and there was a problem with one of my loop where I was appending one variable to one of my array, the variable itself was very heavy (approx 110KB of data). So I would suggest, do a careful inspection of your code.

    Ravish

    0 讨论(0)
  • 2020-11-30 00:18

    Install xdebug and enable profiler trigger. Generate a profiler file, then post the cachegrind file if you still would not be able to tell the source of the problem.

    EDIT: profiler file of the page where the memory leak happens of course!

    0 讨论(0)
  • 2020-11-30 00:18

    This is a known bug in PHP v 5.2 for Windows, it is present at least to version 5.2.3: https://bugs.php.net/bug.php?id=41615

    None of the suggested fixes have helped for us, we're going to have to update PHP.

    0 讨论(0)
  • 2020-11-30 00:18

    I know it's an old thread, but here's my experience getting it resolved.

    My server is a hosted service running Apache.

    My script crashed with out of memory at 6Mb, when my limit Was 256Mb - crazy, yeah?

    It is being called synchronously via an http callback, from javascript running on my client, and crashed after around 550 calls. After much time wasted with incompetent "Escalated Support" guys, my script now magically runs.

    They said all they did was to reset php.ini, but I checked the differences:

    No changes there that I can see that could have a bearing on an Out of Memory error.

    I suspect a memory leak in the web server which my "Escalated Support" guy is hiding under the guise of resetting the php.ini. And, really, I'm not a conspiracy theorist.

    0 讨论(0)
  • 2020-11-30 00:21

    Please note that the error is Out of memory and is not Allowed memory size [..] exhausted.

    So the memory leak is elsewhere on the system. It's possible that mysql server use a lot of system memory after this heavy query, leaving apache/php without it physical and swap.

    This should explain the error always on the same line (and/or in the same script).

    0 讨论(0)
提交回复
热议问题