CodeIgniter Forums
Session files - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Session files (/showthread.php?tid=71037)



Session files - donpwinston - 06-28-2018

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?


RE: Session files - kilishan - 06-28-2018

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.


RE: Session files - dave friend - 06-28-2018

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.


RE: Session files - ballpumpe - 04-27-2021

(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.

When GC happens, this should be ran.

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 () {
    $gc = new \CodeIgniter\Session\Handlers\FileHandler;
    if ($gc->gc(1800)) {
        echo "success";
    }
});

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