Geoff Maddock
Geoff Maddock

Reputation: 1802

How do you trigger session garbage collection in PHP < 5.4?

I need to force session garbage collection to trigger in PHP, and I'm using version 5.3.3. I see in PHP 5.4, you can call:

SessionHandler::gc()

What is the best method to get the same result given the PHP version I am using?

Upvotes: 2

Views: 1539

Answers (1)

Marc B
Marc B

Reputation: 360662

For older PHPs, you have to fiddle with the GC probability settings:

session.gc_probability 1
session.gc_divisor 1

giving a 100% chance of the GC being run on every request. Of course, this would be a major performance hit, so you might want to put those overrides into a conditional block in apache and allow them to be set only for a particular IP or user.

Docs: http://php.net/manual/en/session.configuration.php#ini.session.gc-probability

Upvotes: 4

Related Questions