php system_error ai_generated true

警告: session_start(): Session GC 失败,位于 /var/www/app/src/Session/SessionManager.php:35

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

ID: php/session-gc-probability-high

其他格式: JSON · Markdown 中文 · English
80%修复率
86%置信度
1证据数
2024-01-10首次发现

版本兼容性

版本状态引入弃用备注
PHP 7.4 active
PHP 8.0 active
PHP 8.1 active
PHP 8.2 active
PHP 8.3 active

根因分析

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

English

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

官方文档

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

解决方案

  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.

无效尝试

常见但无效的做法:

  1. 80% 失败

    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% 失败

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