I'm having some trouble understanding session timeouts in regards to Magento/Apache/PHP. We are converting from IIS/ASP. Initially I set the timeout in the admin, System->Configuration->Web->Session Cookie Management->Cookie Lifetime to 20 minutes. That is working fine, but I noticed that the session does not terminate when the browser is closed. So I set Cookie Lifetime to 0, which ends the session when the browser closes, but now it doesn't after a span of inactivity.

I was thinking that PHP would take care of it since it has the default of 24 minutes. But maybe I need to do something in Apache as well. Seems like we adjusted IIS and ASP before.

Anyway my goal is to have the Magento session end on browser close and after 20 or so minutes. What settings or combinations of settings do I need?

1 Answer 1


If I recall correctly, ultimately Magento will rely on session.gc_maxlifetime, despite what you've set in the store admin area.

On top of that, there is always the chance that the garbage collector trashes your session based on session.gc_divisor and session.gc_probability.

After setting your cookie lifetime in the admin to 1200 (in seconds, remember), check your php.ini settings to make sure session.gc_maxlifetime is set to something on the high end of what you may want to set in Magento (or on other applications on the same server).

86400 (one day) is a reasonable setting.

As to how to have the session end after a user closes their browser (aside from just setting session to 0), I'm not sure this is possible.

  • I read a bit about the settings you mentioned. What started my confusion is I left my browser open overnight and this morning my cart was still active along with my checkout progress. Does that make any sense given I'm using the default values? Could it be the probability didn't kick in because I'm the only visitor on my dev site?
    – gwgeller
    Aug 12, 2014 at 19:35
  • I've had the same questions previously, see: stackoverflow.com/questions/7828975/…
    – pspahn
    Aug 12, 2014 at 21:20
  • I found that gc_maxlifetime was being overridden in my virtual host. I have set it back to 1440 and am testing.
    – gwgeller
    Aug 15, 2014 at 19:46
  • Also gc_probability is 0. Session clean up is handled by the cron in /etc/cron.d/php5 every 30 minutes.
    – gwgeller
    Aug 15, 2014 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.