Steve
Steve

Reputation: 21499

How many variables is to many when storing in _SESSION?

I'm looking for an idea of best practices here. I have a web based application that has a number of hooks into other systems. Let's say 5, and each of these 5 systems has a number of flags to determine different settings the user has selected in said systems, lets say 5 settings per system (so 5*5).

I am storing the status of these settings in the user sesion variables and was wondering is that a sufficient way of doing it?

I'm learning php as I go along so not sure about any pitfalls that this could run me into!

Upvotes: 0

Views: 474

Answers (4)

Spudley
Spudley

Reputation: 168695

I've seen PHP $_SESSIONs that contain arrays of hundreds of objects, so your little 5x5 matrix is tiny by comparison.

(The hundreds of ojects examples that I've seen are, however, a bit excessive, so just to clarify that I'm not condoning going that far! ;-))

Upvotes: 0

Seldaek
Seldaek

Reputation: 42036

You have to realize that the session usually times out after 20minutes and then the data is garbage collected eventually. 25 values in the session isn't too much, but be sure you store them somewhere a bit more persistent if you can't afford to lose that data.

Upvotes: 2

Mchl
Mchl

Reputation: 62387

There's no size limit on session (apart from obvious memory and disk quota limit). Just keep it sane and don't put your entire database in it.

Upvotes: 2

James Kingsbery
James Kingsbery

Reputation: 7486

It's probably fine for a prototype, but you probably want to consider persisting these settings in MySQL/Postgres/Mongo/etc.

In terms of the number of settings that PHP can support, it depends on how many users you have and how much memory your production environment has.

Upvotes: 0

Related Questions