CodeIgniter Forums
Store session in db or in file - 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: Store session in db or in file (/showthread.php?tid=79806)



Store session in db or in file - pippuccio76 - 07-28-2021

hi , where is the best practice store session in file or in db ?
How many time delete file or record in db ? do it automatically with a cronjob ?


RE: Store session in db or in file - paliz - 07-29-2021

i prefere session file


RE: Store session in db or in file - Kenneth Kipchumba - 07-29-2021

(07-28-2021, 12:33 PM)pippuccio76 Wrote: hi , where is the best practice store session in file or in db ?
How many time delete file or record in db ? do it automatically with a cronjob ?

Read this tip from the user guide -> https://codeigniter.com/user_guide/libraries/sessions.html#bonus-tip


RE: Store session in db or in file - includebeer - 07-29-2021

It depends on your use case. I have an application hosted on 2 web servers behind a load balancer. They both connect to the same database. So I set the session in the database. That way it doesn't start 2 separate session on each server.

If you need to read all the active sessions of your users, it's easier with a database.

Depending on the amount of data saved in the session and the quantity of users, it may be faster or slower with on method or the other. Try them all and see what best fit your use case.


RE: Store session in db or in file - pippuccio76 - 08-01-2021

(07-29-2021, 04:22 PM)includebeer Wrote: It depends on your use case. I have an application hosted on 2 web servers behind a load balancer. They both connect to the same database. So I set the session in the database. That way it doesn't start 2 separate session on each server.

If you need to read all the active sessions of your users, it's easier with a database.

Depending on the amount of data saved in the session and the quantity of users, it may be faster or slower with on method or the other. Try them all and see what best fit your use case.

hi , i see that the env sample file are changed , there is a documentation for every line of env file ? Do you delete session file or session db programmatically?


RE: Store session in db or in file - includebeer - 08-01-2021

(08-01-2021, 11:04 AM)pippuccio76 Wrote: Do you delete session file or session db programmatically?

No. The framework takes care of that.


RE: Store session in db or in file - tgix - 08-02-2021

Just wand to add Redis as a possible storage for sessions. We run in an AWS environment with Fargate and ECS workers and an ElastiCache cluster handling the sessions.