Re: Keeping session info in $_SESSION or in database?

From: Date: Mon, 15 Aug 2011 19:05:57 +0000
Subject: Re: Keeping session info in $_SESSION or in database?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-314529@lists.php.net to get a copy of this message
On 15 Aug 2011, at 19:43, LAMP wrote: > This is THE question that bothers me for a while... I always was keeping session info, like > user ID, organization ID, selected book ID... within $_SESSION array. Main reason is to access and > maintain it faster than keeping them inside session table. And, also, one less mysql connection. > Though, in last project the $_SESSION grow up to around 30, even 50 elements of the array. And > several people mentioned it's better to keep so big session data in mysql than in $_SESSION. > > My question is pros and cons $_SESSION vs. mysql session. And, if the amount of data is only > reason, when is better to keep all data in $_SESSION and when to store them in mysql? 1) 30-50 array elements says nothing about the size of the data. That's like saying you have 30-50 piece of paper and assuming that means they contain a lot of text. If each array element is simply a number then 30-50 is not even close to being big. 2) Size of data is never good reason why you'd switch your session storage from files to a database. The data still needs to be read and unserialised at the start of a request, and serialised and written back at the end. In fact, with larger amounts of data you may find file-based storage to be faster. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/

« previous php.general (#314529) next »