Session files |
I've noticed that in my writable/sessions directory there are a zillion files. Do these keep accumulating or are they deleted at some point?
Simpler is always better
It's handled by PHP's own garbage collection routine, which by default on many systems run every 100th request. It's possible there's a bug in the system, but largely dependent on what OS you're running and your server settings. Here's a decent explanation of what's going on and ways to work with it, even though it uses Symfony and Laravel for examples.
When GC happens, this should be ran.
Clean up is determined by the PHP runtime configuration items gc_probability divided by gc_divisor. That ratio defines the probability that the GC (garbage collection) process is started on any session initialization. So, given 1/100 there is a 1% chance that the GC process starts. (docs)
I've highlighted probability and chance to point out there is no guarantee GC will happen once every 100 times per the 1/100 example. It could happen twice in a row and then not again for 200 (and potentially many more) session initializations. (06-28-2018, 12:38 PM)kilishan Wrote: It's handled by PHP's own garbage collection routine, which by default on many systems run every 100th request. It's possible there's a bug in the system, but largely dependent on what OS you're running and your server settings. Here's a decent explanation of what's going on and ways to work with it, even though it uses Symfony and Laravel for examples. I hate to dig up such an old thread but I have a follow up question that just fits exactly to the topic. If I don't want to rely on PHP's own garbage collection and instead run the gc() method directly via cronjob for example, how do I do this? I tried : /app/Config/Routes.php Code: $routes->get('/gc', function () { but with no success. "ArgumentCountError Too few arguments to function CodeIgniter\Session\Handlers\FileHandler::__construct(), 0 passed in /var/www/app/Config/Routes.php on line 94 and exactly 2 expected" Am I on the right track or completly false with this approach? thanks in advance |
Welcome Guest, Not a member yet? Register Sign In |