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

前端 未结 20 2659
情歌与酒
情歌与酒 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-29 23:58

    For starters, memory_get_peak_usage() will not be helpful here. It will only return the amount of memory which was allocated, and that is the same number which caused the error.

    memory_get_usage will return the active amount of memory which is being allocated when it is called.

    ini_set('memory_limit', '256M'); will set the maximum allowance of PHP's footprint on your systems Memory. If you are getting OOM at 768K, upping it will not fix the problem.

    There is no indication as to what version of PHP you are using, but I would suggest an upgrade immediately. There are several bugs where Zend's Memory Manager fails to deallocate memory, which would lead you exactly to the same problem.

    Are both your local server and your production server running the same version of OS, the same long bit and the same version of PHP? The answer will be no.

    If it is unrelated to the windows malloc() issue, being it is a sub domain and probably within a VirtualHost, and allocating only 768k, it almost sounds like an OS issue.

    Run tasklist from the command prompt when you access your script. Do you see an additional Apache thread, or Memory usage across the processes spike?

    One last idea is, run flush() and/or ob_flush(); after each loop for the table row/column. This should clear your buffer and save you some memory in the event this is where the issue is occurring.

提交回复
热议问题