Fix PHP session.gc_divisor warning and WordPress media OOM

Summary

  • Two issues observed in error_log: session.gc_divisor set to 0, and an Out of memory crash in wp-admin/includes/media.php during image sub-size generation.

Error log excerpt

[17-Aug-2025 17:00:01 UTC] PHP Warning:  PHP Startup: session.gc_divisor must be greater than 0 in Unknown on line 0
[17-Aug-2025 17:03:01 UTC] PHP Warning:  PHP Startup: session.gc_divisor must be greater than 0 in Unknown on line 0
[17-Aug-2025 17:14:45 UTC] PHP Warning:  PHP Startup: session.gc_divisor must be greater than 0 in Unknown on line 0
[17-Aug-2025 17:17:01 UTC] PHP Warning:  PHP Startup: session.gc_divisor must be greater than 0 in Unknown on line 0
[17-Aug-2025 17:30:02 UTC] PHP Warning:  PHP Startup: session.gc_divisor must be greater than 0 in Unknown on line 0
[17-Aug-2025 17:33:01 UTC] PHP Warning:  PHP Startup: session.gc_divisor must be greater than 0 in Unknown on line 0
[17-Aug-2025 17:38:35 UTC] PHP Warning:  PHP Startup: session.gc_divisor must be greater than 0 in Unknown on line 0
[17-Aug-2025 17:39:00 UTC] PHP Warning:  PHP Startup: session.gc_divisor must be greater than 0 in Unknown on line 0
[17-Aug-2025 17:39:14 UTC] PHP Warning:  PHP Startup: session.gc_divisor must be greater than 0 in Unknown on line 0
[17-Aug-2025 17:39:48 UTC] PHP Warning:  PHP Startup: session.gc_divisor must be greater than 0 in Unknown on line 0
[17-Aug-2025 17:39:49 UTC] PHP Fatal error:  Out of memory (allocated 179048448 bytes) (tried to allocate 32768 bytes) in /home/sexymac/public_html/wp-admin/includes/media.php on line 395
[17-Aug-2025 17:39:51 UTC] PHP Warning:  PHP Startup: session.gc_divisor must be greater than 0 in Unknown on line 0
[17-Aug-2025 17:39:51 UTC] PHP Fatal error:  Out of memory (allocated 179048448 bytes) (tried to allocate 32768 bytes) in /home/sexymac/public_html/wp-admin/includes/media.php on line 395

Fix steps

  • Session settings (php.ini or .user.ini):
    • session.gc_probability = 1
    • session.gc_divisor = 1000
    • session.gc_maxlifetime = 1440
  • Memory headroom:
    • memory_limit = 256M (or 512M) and WP_MEMORY_LIMIT/WP_MAX_MEMORY_LIMIT in wp-config.php.
  • Reduce heavy image work (mu-plugin):
    • Remove 1536/2048 sizes, set big_image_size_threshold 2048, JPEG quality ~82.
  • If needed, prefer GD or Imagick in wp-config.php (WP_IMAGE_EDITORS).
  • Pause cron while fixing (DISABLE_WP_CRON true), then re-enable.
  • If a plugin is triggering bulk image jobs, deactivate it first and update after stabilization.

Notes

  • The OOM occurs inside wp_generate_attachment_metadata() when creating sub-sizes for large images or many size variants.

Category: Wordpress

Tags:

Leave the first comment