CodeIgniter Forums
[SOLVED] Session as DatabaseHandler Driver - 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: [SOLVED] Session as DatabaseHandler Driver (/showthread.php?tid=87140)



[SOLVED] Session as DatabaseHandler Driver - superior - 03-17-2023

Hi,

A few days ago i've started to play with DigitalOcean's App Platform to see how CodeIgniter4 runs, all seems to be working fine except for a small thing.

The issue
DigitalOcean rebuilds the application on each publication, this means they will delete everything before publishing the newly commit.
Not an issue for me but the /writable/ folder and it's contents will also be delete, this said I need a different solution for my /session/ folder.

Other folders
The cache folder is only storing information for about 5 minutes so that's not a problem.
The uploads folder is an external bucket so that folder isn't being used on my side, i'm also storing some additional information there.

Solution
CodeIgniter does offer a DatabaseHandler that will use a table named 'ci_sessions' (or a name as you desire).
This will solve the issue for me so the content will not be deleted, i'm unable to find out how this is handled.
Looked through the spark command list but under "Housekeeping" there is no session:cleanup or somehting simulair.

Q: How does CodeIgniter run a cleanup, do i need a command for this?



RE: Session as DatabaseHandler Driver - InsiteFX - 03-17-2023

The session cleanup is usally handled by php.

To cleanup sessions it is recommened to use a CRON Job to clean them up.


RE: Session as DatabaseHandler Driver - superior - 03-18-2023

Thanks for the reply, does this also clean the table with sessions or do i need to create an additional cleanup task?


RE: Session as DatabaseHandler Driver - InsiteFX - 03-18-2023

I would create a cleanup method for it, this way if you need to make changes later it will be easier.


RE: Session as DatabaseHandler Driver - superior - 03-19-2023

Thank you for the reply!
I've created an additional task that will remove sessions older than 3 months.