Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - to store big session array in $_SESSION or in database?

I need to store a big array during the session (currently up to few kB, and I'd limit it to 0.25MB max).

In your opinion and practice, is it better to store it in $_SESSION or in database?

Speed matters, but so does processor/memory usage, as it's on shared host, and I wouldn't want them to shut the site down for resource overuse.

Would you say there's a size range in which $_SESSION can be used with confidence it will work well? (For example 0kb-100kB or whatever your practice/tests showed).

Thanks.

like image 492
CodeVirtuoso Avatar asked Jan 17 '23 21:01

CodeVirtuoso


1 Answers

0.25MB with a sane number of sessions will use less resources if stored in the Session, than in the DB. So the likelyhood of resource overusage is lower with the session.

like image 195
Eugen Rieck Avatar answered Jan 28 '23 17:01

Eugen Rieck