Symfony2缓存会话不是垃圾收集导致磁盘完全问题

So the application is not doing anything with caching, I'm just using the default framework setting in config.yml

framework:
    # ...
    session:         ~

Looking in the

project/app/cache/prod/session 

directory I see session files from 6 months ago and it's causing a DISK FULL error/issue.

If I run the command

df -h

The disk space looks fine, if I run the command

df -i

I see it's full or almost full

for the php.ini it's all default settings, running ubuntu 12.04 LTS and PHP 5.3.x

Why isn't the Garbage Collection working? When I clear the Cache it's fine and cleans up but to my understanding the session should be removed after 4 hours, any ideas?

If anyone else has this issue here is how to fix it:

Here is what is configured in

  • /etc/php5/apache/php.ini
  • /etc/php5/cli/php.ini
  • /etc/php5/fpm/php.ini

( All three are the same )

session.gc_probability = 0
session.gc_divisor = 1000
session.gc_maxlifetime = 1440

I also looked in to

/etc/cron.d/php5 

and it should remove the sessions using this value session.gc_maxlifetime

# /etc/cron.d/php5: crontab fragment for php5
#  This purges session files older than X, where X is defined in seconds
#  as the largest value of session.gc_maxlifetime from all your php.ini
#  files, or 24 minutes if not defined.  See /usr/lib/php5/maxlifetime

# Look for and purge old sessions every 30 minutes
09,39 *     * * *     root   [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) -delete

The problem is my sessions are not in the standard location and are not cleaned up because of this.

Configuring the framwerwork session save_path to:

/var/lib/php5

You can also set this value to the save_path of your php.ini by setting the value to null:

# app/config/config.yml
framework:
    session:
        save_path: null

Docs: