Alex Rivera | Logout

Is it okay to save lots of information in $_SESSION?

Asked 2011-05-03T16:36:05.557
9

I need to store many arrays in $_SESSION to prevent retrieving information from MySQL. Is it okay? How much is "too much" information in $_SESSION or there isn't any "too much"? Thanks.

P.S. Or it's better to use http://php.net/manual/en/book.memcache.php ?

Edit
Report

2 Answers

1

$_SESSION is not for caching.

If you need to cache stuff, then use APC , or Memcached or even Redis.

answered 2011-05-03T16:42:38.473
1

The amount of data in your session will have an effect on performance. If you intend to use files for session, note that php might hit a bottleneck at the disk. Reading, writing and serializing that data might incur heavy disk i/o, which is bad.

As far as a hard upper limit, I suspect those limits are the same as your filesystem's. For example, if you save massive amounts of data to session, and you fill up your disk, you'll not be able to write additional sessions.

Using memcached will alleviate the disk i/o performance issues, as writing and reading from memcached is much faster. Your limits there will be 1MB per session, as per the memcached spec. Your total space for sessions will be the size of the memcache instance you start (dictated by the -m flag when starting the memcache instance).

answered 2011-05-03T17:04:09.713

Your Answer