php system_error ai_generated true

Warning: session_start(): Session GC failed in /var/www/app/src/Session/SessionManager.php:35

ID: php/session-gc-probability-high

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
1Evidence
2024-01-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
PHP 7.4 active
PHP 8.0 active
PHP 8.1 active
PHP 8.2 active
PHP 8.3 active

Root Cause

PHP's session garbage collection (GC) fails due to permission issues on the session save path, disk full, or a misconfigured GC probability that triggers too frequently.

generic

中文

PHP 的会话垃圾回收(GC)失败,原因是会话保存路径的权限问题、磁盘已满或 GC 概率配置不当导致触发过于频繁。

Official Documentation

https://www.php.net/manual/en/session.configuration.php#ini.session.gc-probability

Workarounds

  1. 90% success Fix permissions on the session save path: run 'sudo chmod 733 /var/lib/php/sessions' and 'sudo chown www-data:www-data /var/lib/php/sessions' (adjust user/group as needed).
    Fix permissions on the session save path: run 'sudo chmod 733 /var/lib/php/sessions' and 'sudo chown www-data:www-data /var/lib/php/sessions' (adjust user/group as needed).
  2. 85% success Check disk space with 'df -h' and free up space if necessary. If using tmpfs for sessions, ensure enough memory is allocated.
    Check disk space with 'df -h' and free up space if necessary. If using tmpfs for sessions, ensure enough memory is allocated.
  3. 75% success Reduce GC probability by setting session.gc_probability=1 and session.gc_divisor=1000 in php.ini to trigger GC once every 1000 requests, reducing load.
    Reduce GC probability by setting session.gc_probability=1 and session.gc_divisor=1000 in php.ini to trigger GC once every 1000 requests, reducing load.

中文步骤

  1. Fix permissions on the session save path: run 'sudo chmod 733 /var/lib/php/sessions' and 'sudo chown www-data:www-data /var/lib/php/sessions' (adjust user/group as needed).
  2. Check disk space with 'df -h' and free up space if necessary. If using tmpfs for sessions, ensure enough memory is allocated.
  3. Reduce GC probability by setting session.gc_probability=1 and session.gc_divisor=1000 in php.ini to trigger GC once every 1000 requests, reducing load.

Dead Ends

Common approaches that don't work:

  1. 80% fail

    Setting session.gc_probability=0 disables GC entirely, which prevents the warning but leads to session file accumulation and potential disk space issues.

  2. 65% fail

    Increasing session.gc_divisor to 1000 reduces GC frequency but does not fix underlying permission or disk problems; the warning may still appear sporadically.