Skip to content

hotfix: enable PHP session garbage collection on OpenLiteSpeed stack - #20

Open
nabil1440 wants to merge 1 commit into
mainfrom
fix/ols-session-gc
Open

hotfix: enable PHP session garbage collection on OpenLiteSpeed stack#20
nabil1440 wants to merge 1 commit into
mainfrom
fix/ols-session-gc

Conversation

@nabil1440

@nabil1440 nabil1440 commented Jul 28, 2026

Copy link
Copy Markdown

Issue

Ref: flywp/flywp-client-issues#48

On the OpenLiteSpeed (OLS) stack, PHP session files pile up in
/var/lib/php/sessions indefinitely — no garbage collection ever runs at
the PHP/OLS layer, unlike nginx sites which clean up normally.

Root cause: lsphp installs Debian's php.ini-production, which ships
session.gc_probability = 0. That is Debian's convention because it offloads
session cleanup to a sessionclean cron job. But that cron is not present in
the OLS container, the bundled sessionclean targets apache2/cgi/fpm SAPI
paths that do not exist in the lsws layout, and no cron daemon runs in the
container anyway. With built-in GC disabled and nothing replacing it, stale
sess_* files accumulate forever. (nginx sites build on php:*-fpm-alpine,
which ships no php.ini, so PHP's compiled defaults keep GC enabled.)

Fix

Re-enable PHP's built-in probabilistic session GC via php/ols.ini:

  • session.gc_probability = 1
  • session.gc_divisor = 100
  • session.gc_maxlifetime = 1440

ols.ini is bind-mounted into lsphp's config scan dir
(.../lsphpXX/etc/php/X.Y/mods-available/), which overrides the base
php.ini, so these values take effect on the next lsphp restart. New OLS
sites pick this up on clone; existing sites on their next update-php.sh run.

Summary by CodeRabbit

  • Bug Fixes
    • Improved PHP session cleanup by enabling automatic garbage collection.
    • Configured session expiration and cleanup behavior to prevent stale sessions from accumulating.

lsphp installs Debian's php.ini-production, which sets
session.gc_probability = 0 and offloads cleanup to a sessionclean cron
that is not present in the OpenLiteSpeed container. With built-in GC
disabled and no cron running, stale sess_* files accumulate in
/var/lib/php/sessions indefinitely.

Re-enable PHP's probabilistic GC via ols.ini, which is mounted into
lsphp's config scan dir and overrides the base php.ini.

Fixes flywp/flywp-client-issues#48
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5c6e6077-9cc7-4afa-8978-a8875796fdb4

📥 Commits

Reviewing files that changed from the base of the PR and between 6862c2b and 16e72b1.

📒 Files selected for processing (1)
  • php/ols.ini

Walkthrough

PHP session garbage collection is explicitly configured in php/ols.ini to probabilistically remove stale session files using PHP’s built-in cleanup mechanism.

Changes

Session garbage collection

Layer / File(s) Summary
Configure PHP session cleanup
php/ols.ini
Adds session.gc_probability, session.gc_divisor, and session.gc_maxlifetime settings with comments describing stale session cleanup under /var/lib/php/sessions.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Poem

A rabbit hops through sessions neat,
Clearing stale files from every seat.
With chance and lifetime set just right,
PHP keeps the directory light.
“No cron,” I twitch, “what a delight!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: enabling PHP session garbage collection on the OpenLiteSpeed stack.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ols-session-gc

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant