Welcome Guest, Not a member yet? Register   Sign In
Session table redundant records problem

(This post was last modified: 10-07-2018, 07:17 AM by dave friend.)

My advice is to not worry so much about the number of old session records in the table. The overhead of tracking each record on regeneration (or expiration) is not worth it.

You may want to adjust the session.gc_probability to session.gc_divisor ratio to increase the chance of garbage collection happening. Howerver, using PHP GC can cause a big performance hit. This article does a good job of showing the problem.

This article also discusses the performance bottleneck of session garbage collection. It suggests the very interesting idea of offloading session GC to the framework by way of a CRON job. The article shows a Laravel example, but the concept could be easily recreated in CI.

Garbage collection aside, I think that using files is the better way to go for most single-server sites. Consider the following criteria.

When to Use a Database for Sessions:
  1. You have multiple web servers.
  2. You are likely to add or remove servers
  3. You don’t want session data to be lost when adding or removing servers.
If you don’t meet these 3 criteria, you can safely stick with the default file storage mechanism.

That list comes from the article PHP Sessions in Depth.

Even if the traffic level is... robust, files tend to use fewer system resources than a DB. Most benchmarking I can find shows files to be faster as the number of sessions grows.

If you are dealing with a high-volume, multi-server site, then a combo of DB, and Redis or Memcache[d], deserves serious consideration.

Messages In This Thread
RE: Session table redundant records problem - by dave friend - 10-07-2018, 07:09 AM

Theme © iAndrew 2016 - Forum software by © MyBB