CodeIgniter Forums
Manage Session folder - 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: Manage Session folder (/showthread.php?tid=82677)



Manage Session folder - chakycool - 08-08-2022

Hi,
I have noticed that my 'writable/session' folder on the server is getting massive. Is there a way to flush/delete these files automatically. 
Thanks.


RE: Manage Session folder - superior - 08-08-2022

If you manage your own server:

> https://www.codeigniter.com/user_guide/libraries/sessions.html#session-preferences
> https://www.php.net/manual/en/function.session-gc.php


RE: Manage Session folder - chakycool - 08-08-2022

Thanks for the reference.
Below is my setting but it's not deleting the files.

$sessionRegenerateDestroy = false;


RE: Manage Session folder - captain-sensible - 08-08-2022

i'm on linux , this cleared my session dir and left the index.html intact
Code:
sudo rm                            /srv/http/ads.com/writable/session/ci_*

So if you set up a cron job as root , using something similar at a good estimated time interval , then that would periodically clear,

I assume the server is linux OS ?


RE: Manage Session folder - ozornick - 08-08-2022

Do not use manual removal. When switch to table storage, you need to generate new cleanup code.
Set session.gc_probability or execute session_gc() in cron script. The function will work with tables and files, comparing session times


RE: Manage Session folder - chakycool - 08-08-2022

Hi All,

Yes I'm on Linux (ubuntu). I thought Ci was capable to clean the sessions it self.
I got about 4 separate sites running via virtual servers so I'm not quite sure how I can clean all 4 session folders via "session_gc()" with cron.


RE: Manage Session folder - ozornick - 08-09-2022

Create controller with run() method
Write session_gc() in action
Set task to cron: * * * * * wget -O http://site.com/cron/run


RE: Manage Session folder - chakycool - 08-09-2022

Thanks Ozornick. Your solution worked perfect.