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

- **ID:** `php/session-gc-probability-high`
- **领域:** php
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| PHP 7.4 | active | — | — |
| PHP 8.0 | active | — | — |
| PHP 8.1 | active | — | — |
| PHP 8.2 | active | — | — |
| PHP 8.3 | active | — | — |

## 解决方案

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.
   ```

## 无效尝试

- **** — Setting session.gc_probability=0 disables GC entirely, which prevents the warning but leads to session file accumulation and potential disk space issues. (80% 失败率)
- **** — Increasing session.gc_divisor to 1000 reduces GC frequency but does not fix underlying permission or disk problems; the warning may still appear sporadically. (65% 失败率)
