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

前端 未结 20 2560
情歌与酒
情歌与酒 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:01

    Just to recap (I'm adding this answer quite a distance from the original question):

    • PHP is unable to allocate what appears to be a small amount of memory
    • the current memory usage at the time the error occrs + the requested amount is less than the memory limit currently in force
    • the system has 6Gb available for use by PHP when this occurs
    • since the problem is resolved by restarting apache - it's apache which is preventing the memory from beig available to PHP

    If these are all valid then the only possible explanation is that the 6Gb is very fragmented - which I think is a little unlikely. You didn't say how PHP is invoked from Apache - mod_php? fpm? Fcgi?

    I would start by examining each of the above predicates - particularly the free memory one. How do you know that there's 6Gb free when the error occurs? A more likely cause is that there's a memory leak occurring which you're not spotting.

    You've not provided any details of how apache is configured; I'd also have a look at reducing MaxRequestsPerChild and MaxMemFree. (I'm not very familiar with worker apache where this will apply per thread - really you need a limit per process). If you provided the core setting from the apache config then maybe we could make further suggestions.

    Unless you are using Ajax extensively, make sure your keepalive time is 2 or less.

提交回复
热议问题