Home » Tutorials & Troubleshooting » How to Fix “PHP Startup: session.gc_divisor must be greater than 0” in WordPress

How to Fix “PHP Startup: session.gc_divisor must be greater than 0” in WordPress

Share this article:

If you opened your wp-content/error_log file only to find it filled with line after line of repeating PHP startup warnings, you are not alone. One of the most persistent background warnings on WordPress sites looks like this:

While this warning rarely crashes a website, it can quickly bloat your server’s error_log file to hundreds of megabytes, taking up precious disk space and masking real critical errors.

In this guide, we’ll explain the simple math behind why this error happens and walk through the exact steps to eliminate it for good.

Why Is This Warning Happening?

To keep your server from filling up with old temporary user data, PHP runs an automated cleanup routine called Garbage Collection (GC). Every time a visitor loads a page on your blog, PHP calculates whether it should sweep the server’s session folder using a simple math formula:

$$\text{Probability of Cleanup} = \frac{\text{session.gc\_probability}}{\text{session.gc\_divisor}}$$

The Problem: Division by Zero

If your hosting server’s default configuration leaves session.gc_divisor set to 0, PHP attempts to calculate the probability and realizes it is trying to divide by zero—a mathematical impossibility.

Because PHP cannot complete the equation when initializing a page request, it throws the PHP Startup: session.gc_divisor must be greater than 0 warning directly into your log file before the page even finishes loading.

How to Fix It (3 Proven Solutions)

Depending on your server architecture, here are the three ways to ensure session.gc_divisor is set to a valid number greater than zero (typically 100 or 1000).

Method 1: Update Your .user.ini File (Best for FastCGI / PHP-FPM)

Most modern WordPress hosts use FastCGI or PHP-FPM. In these environments, PHP configuration rules should be placed in a .user.ini file located in your root WordPress directory.

(If you are unsure how to connect to your site to edit this file, check out our guide on how to connect via Core FTP LE).

  1. Open (or create) the .user.ini file in your WordPress root directory.
  2. Add or update the following session lines:

Ini, TOML

; Fix PHP Session Garbage Collection Settings
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 28800
  1. Save and upload the file back to your server.

Important: Do not add these php_value directives directly into your .htaccess file if you are on a FastCGI server, as this will trigger an Apache crash. Read our post on why .htaccess rules cause 500 Internal Server Errors for details.

Method 2: Force Settings in wp-config.php (Instant Override)

If your web host ignores .user.ini files or caches them on a delay, you can force WordPress to set these parameters at the application level every time PHP boots up.

  1. Connect to your server via FTP and open wp-config.php.
  2. Scroll down near the bottom, right above the line that says /* That's all, stop editing! Happy publishing. */.
  3. Paste these two runtime override lines:
// Force valid session garbage collection math
@ini_set('session.gc_probability', '1');
@ini_set('session.gc_divisor', '1000');
  1. Save and re-upload the file.

Method 3: Edit php.ini via cPanel (MultiPHP INI Editor)

If you have access to cPanel or a VPS control panel:

  1. Log into your hosting dashboard and open MultiPHP INI Editor.
  2. Select the domain or path for your WordPress installation.
  3. Locate session.gc_divisor and change its value from 0 to 1000.
  4. Set session.gc_probability to 1.
  5. Save changes.

How to Verify the Fix

Because error_log files only append new entries and never auto-delete past warnings, existing lines will remain until you clear them manually.

  1. Clear the Log: Open your wp-content/error_log file via FTP, delete all text inside, and save it as a 0-byte blank file (or delete the file entirely so WordPress can regenerate it).
  2. Trigger Page Loads: Open a fresh browser window and click through 3 to 4 pages on your blog.
  3. Check FTP: Refresh your FTP directory. If the error_log file remains empty (or does not reappear), the warning is officially resolved!

Summary

By ensuring session.gc_probability is set to 1 and session.gc_divisor is set to 1000, you give PHP a clean $1/1000$ ($0.1\%$) chance of running session maintenance on any given page view. This satisfies PHP’s mathematical requirements, stops startup warnings from firing, and keeps your server logs clean and easy to read.

Share this article:
Follow Siamak Ensafi:

Designer, Marketer, Owner

Siamak Ensafi is a self-taught creative professional with expertise in graphic design, web development, and affiliate marketing. He specializes in crafting visually compelling logos, banners, landing pages, and digital graphics that blend form and functionality. With a passion for innovation and a keen eye for detail, Siamak brings unique branding solutions to life across modern web platforms. Outside of his design work, he’s an avid cycling enthusiast, finding inspiration and clarity on the open road.

2 Responses

  1. […] Inspecting Error Logs: You can navigate to wp-content/error_log to troubleshoot silent PHP errors. If you see repeating warnings in your log, read our full guide on how to fix the PHP session.gc_divisor startup warning in WordPress. […]

  2. […] via .user.ini or wp-config.php, you can safely clear out annoying server warnings, such as resolving the session.gc_divisor error log warning in WordPress, without risking an Apache […]

Leave a Reply

Your email address will not be published. Required fields are marked *