473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Questions on size of session

Hey! Is there some sort of limit on how much one could store in a
session as far as amount of data?

Is it advisable to store a LOT of data in the session when a user logs
in to save queries to the dbase while the user is browsing the site?

Does this depend somehow on how many sessions are going on at once?

Any input would be appreciated, thanks!

Jul 17 '05 #1
5 9594
There is really no limit to the size of session data, but I would strongly
advise AGAINST storing large volumes of table data in a session array to
avoid reading from the database again. That is NOT what sessions ere
designed for. You should only store in the session array what is necessary
to maintain state between requests. If other data can be read from the
database, then read it from the database. There will be little or no
difference in performance.

--
Tony Marston

http://www.tonymarston.net
"Timin Uram" <so*******@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hey! Is there some sort of limit on how much one could store in a
session as far as amount of data?

Is it advisable to store a LOT of data in the session when a user logs
in to save queries to the dbase while the user is browsing the site?

Does this depend somehow on how many sessions are going on at once?

Any input would be appreciated, thanks!

Jul 17 '05 #2
Timin Uram wrote:
Hey! Is there some sort of limit on how much one could store in a
session as far as amount of data?
No, session are stored (serialized $_SESSION) as flatfile or in a database.
So the limit depends on the size on your system.

Is it advisable to store a LOT of data in the session when a user logs
in to save queries to the dbase while the user is browsing the site?
In general: No.
It is advisable to store a few essential pieces of information in your
session, and query your database when needed, based on these values.
eg: suppose you have a huge usertable (including adresses and such)

when user logs in:
$_SESSION["userid"] = $someuserid;
and maybe:
$_SESSION["username"] = $someusername;

Like that you can easily say:
hello <?= $_SESSION["username"] ?>, welcome here and there.

But you typically do not store everything you know of the user in a SESSION,
because userid is enough for you to fetch the information when you need it.


Does this depend somehow on how many sessions are going on at once?
Yes.
If you have 1 MB per session, 1000 session will clearly give you some
performancepenalty.


Any input would be appreciated, thanks!


However: I have been in situation I used a session to store a huge amount of
information.
In that particular situation, I calculated all the information I needed for
a complex image, and then had to feed it to an imagecreationscript.
That image was on the same page as where all the calculation were performed.
But the imageproducing script was a seperate script, so it needed the
information too.
So I stored in in a session.
After the imagescript was done, it deleted the information from the session.

Bottomline: Avoid storing unneeded information in a session.
Unneeded as in: I can fetch it quickly when needed based on a userid or
something like that.

just my 2 cents.

Regards,
Erwin Moller
Jul 17 '05 #3
No, it's not advisable to store a lot of data in a session. As others
have noted, it's not a idea to duplicate data from a database. Even if
you really need some sort of caching mechanism, you wouldn't store the
data in a session. The problem is that PHP rewrites the session data
for every request. And as we all know writing to disk is a rather slow
operation.

If you really need to do it, serialize the array and store it in a
separate file.

Jul 17 '05 #4
ch***********@hotmail.com wrote:
No, it's not advisable to store a lot of data in a session. As others
have noted, it's not a idea to duplicate data from a database. Even if
you really need some sort of caching mechanism, you wouldn't store the
data in a session. The problem is that PHP rewrites the session data
for every request. And as we all know writing to disk is a rather slow
operation.

If you really need to do it, serialize the array and store it in a
separate file.


Just curious: Isn't that excactly what a session does between request?
I mean: Isn't that excactly as slow as storing it in a session?

Regards,
Erwin Moller

Jul 17 '05 #5
Erwin Moller wrote:
ch***********@hotmail.com wrote:
No, it's not advisable to store a lot of data in a session. As others
have noted, it's not a idea to duplicate data from a database. Even if
you really need some sort of caching mechanism, you wouldn't store the
data in a session. The problem is that PHP rewrites the session data
for every request. And as we all know writing to disk is a rather slow
operation.

If you really need to do it, serialize the array and store it in a
separate file.


Just curious: Isn't that excactly what a session does between request?
I mean: Isn't that excactly as slow as storing it in a session?


Aha, I think understand what you mean:
If you need that bunch of serialized data only 1 in 10 pages, you only
unpack it once in 10 pages.
Session is of course packing/unpacking for every request.

doh...

*Erwin runs off to find some coffee*

Regards,
Erwin Moller
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Marcus | last post by:
Hi All, First, just wanted to say that I found what I thought was a very helpful tutorial on sessions in case anyone out there has questions on them: ...
4
by: Colin Steadman | last post by:
I've create a simple survey using ASP. Its finished and works, but one aspect of my coding is annoying me and I cant figure out a better way of doing it. Basically the questions are stored in...
9
by: eitan | last post by:
Hello, I am using Microsoft Visual Studio 2003 .NET. I have several question, please. 1) I have a connection to the database, which I create it at login, by application("conMain") (I have...
3
by: raj | last post by:
hi, I have 4 forms all having 40 fields in datagrid,I have two textBoxes for date and country, according to my requirement if i have set date and country in one form then if i go to another form...
2
by: G.E.M.P | last post by:
High Level Session Handling Design for a Shopping cart 0) What am I missing? 1) How does OSCommerce do it? I'm thinking about building a shopping cart from scratch, using a library of dynamic...
2
by: Rishan | last post by:
Hi, I'm trying to debug a memory leak on a production application for one of my clients. The aspnet_wp.exe, if left to grow, will eventually consume enough memory to throw an out of memory...
16
by: marc_r_bertrand | last post by:
To all asp/db pros: The quiz code below works. But there is a problem when too many questions are answered (radio buttons clicked). I am not an asp pro. So, is there a pro out there or an...
2
by: gvijayasurya | last post by:
11. What are the different tables present in mysql, which type of table is generated when we are creating a table in the following syntax: create table employee(eno int(2),ename varchar(10)) ? 12....
1
by: chrisj | last post by:
I'm using freeASPupload and got some assistance integrating to a Member script. It works successfully. In this modified version there are two groups that use this upload script. Members of one...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.