Questions? Feedback? powered by Olark live chat software
Knowledgebase
Author Avatar

PHP Invoked OOM-killer Error

Written by: on 27 August 2014 04:04 PM 27 August 2014 04:04 PM

Step by step tutorial on how to fix the PHP invoked OOM killer error. Read steps to fix yourself.

If your linux server does not have enough memory, it may crash due to trying to overcommit memory for application requests.

If your server becomes unresponsive and after restarting, look at the logs at /var/log/messages

If you find an errors similar to the following.

This one means that a process was killed as it was using too much memory, or memory was not available:

Aug 27 15:25:31 vps kernel: Out of memory: Kill process 19952 (php) score 28 or sacrifice child
Aug 27 15:25:31 vps kernel: Killed process 19952, UID 502, (php) total-vm:273544kB, anon-rss:11244kB, file-rss:936kB

This error is a fatal error meaning the kernel tried to overcommit memory for an application (in this case php) and failed. The kernel call trace is the output when a kernel panic occurs:

Aug 27 15:25:31 vps kernel: php invoked oom-killer: gfp_mask=0x200da, order=0, oom_adj=0, oom_score_adj=0
Aug 27 15:25:31 vps kernel: php cpuset=/ mems_allowed=0
Aug 27 15:25:31 vps kernel: Pid: 20001, comm: php Not tainted 2.6.32-358.2.1.el6.x86_64 #1
Aug 27 15:25:31 vps kernel: Call Trace:

This means your server essentially ran out of memory. You should consider adding an extra GB of RAM to your system, see: https://www.vpsblocks.com.au/support/Knowledgebase/Article/View/86/0/how-to-upgrade-your-memory--ram

You can also prevent your kernel from overcommitting memory in the future, by editing a file:

pico /etc/sysctl.conf

Enter the line: 

vm.overcommit_memory = 2

CTRL O to save the file
CTRL X to exit

Now type:

sysctl vm.overcommit_memory=2

This will make the value active in this session without requiring a restart. This may have adverse affects on your server however.

There is an explanation about this here: http://www.hskupin.info/2010/06/17/how-to-fix-the-oom-killer-crashe-under-linux/

You can also configure your server to reboot when an OOM-Killer event occurs:

pico /etc/sysct.conf

Enter the lines:

# panic kernel on OOM
vm.panic_on_oom = 1
# reboot after 5 sec on panic
kernel.panic = 5

CTRL O to save the file
CTRL X to exit

Now type:

sysctl vm.panic_on_oom=1
sysctl kernel.panic=5

(2 vote(s))
Helpful
Not helpful