How to diagnose out of memory killed PHP-FPM

When PHP-FPM is killed due to out-of-memory errors, it usually means that the PHP process has exceeded the memory limit set in the PHP configuration or that the server does not have enough memory available to allocate to the PHP process. To diagnose and resolve this issue, you can follow these steps:

  • Check the PHP-FPM error log:
    • On Linux systems, the log file is usually located at /var/log/php-fpm.log.
    • On Windows systems, the log file can be found in the PHP installation directory.

Look for any error messages related to memory allocation or out-of-memory errors.

  • Check the PHP configuration:
    • Open the php.ini file and look for the memory_limit directive. By default, it is set to 128M. Consider increasing it if your server has enough memory available.
  • Check the server’s available memory:
    • Use the “free” command in the terminal to check the amount of available memory on your server. If the server does not have enough memory to allocate to the PHP process, consider upgrading the server or optimizing your code.
  • Analyze your PHP code:
    • If you’ve ruled out memory limitations and server resources, it may be time to analyze your code to determine why it’s consuming too much memory. Consider using a profiler tool like XDebug or Blackfire to pinpoint areas of your code that may be causing excessive memory usage.

By following these steps, you should be able to diagnose and resolve the out-of-memory issues with PHP-FPM.