PHP-FPM getting OOM killed

Hi,

I have issues with my PHP-FPM process getting killed every few weeks. The only trace I have is from the service log.

Jul 03 18:02:14 systemd[1]: php8.2-fpm.service: A process of this unit has been killed by the OOM killer.
Jul 03 18:02:16 systemd[1]: php8.2-fpm.service: Failed with result 'oom-kill'.

I would firstly like to know why it happens and, if possible, prevent it. And secondly, to restart it automatically once it happens. I’m not interested in resorting to “hacks”.

According to my monitoring systems, there is plenty of memory available (some 2 out of 8 GB used), and usage levels are stable, so it must be either a very intense spike that the monitor doesn’t register, or something else. How can I find out where the issue occurs, or otherwise gain more information?