Magento Garbage collection | News | PHPro
What's new in our world

Magento Garbage collection

03 January 2012

On some Magento installations, the number of session files in the var/session folder can grow out to millions. This is because the expired session files are not cleaned up. All this files have a negative impact on your server performance: it uses disk-space and slows down your server. In some cases, your Magento webshop will go down because the disk space is full or there are too many files in a folder.

The cleanup of the Magento session files (or records in the database) is done by 'garbage collection'.
In your php.ini, there are the following directives:

  • session.gc_probability
  • session.gc_divisor
  • session.gc_maxlifetime

The session.gc_maxlifetime is the maximum lifetime when a session is valid. Sessions older than this interval, will be seen as garbage. The next time the garbage collection process starts, this expired session files are cleaned up.

If there are a million of session files in your Magento installation, it's because the garbage collection process never starts. Mostly the session.gc_probability and session.gc_divisor are not well set in your php.ini.
If the session.gc_probability is 1 and the session.gc_divisor is 100, this will mean that there is a 1 chance in 100 requests that the garbage collection starts.
In some debian installations, the default value of the gc_probability is 0. This will mean that there are 0 chances to start the garbage collection and the problem of a million session files will apear.

By setting the value to 1 in your php.ini or .htaccess, the problem is mostly solved.

Share