0

I have a problem with php session. I have a function where temporary array data are stored in a session before I save it to database. Problem is that when that data in session reaches a hundred or more, the data in that session clears again.

Now, I know it's not a good practice to save too much data in session but I have no choice, this is what they want.

So is there a way to increase the capacity of session? any help would be highly appreciated!

Thanks in advance.

Rick
  • 1
  • 1
  • 1
  • 2
    "hundred or more" of what? ps: "this is what they want" --- are you a professional or not? If they know better - why they don't do that work? What if they asked to write the code sitting in a poll underwater (just because they want)? – zerkms Aug 04 '11 at 01:13
  • http://stackoverflow.com/questions/217420/ideal-php-session-size – Jacek Kaniuk Aug 04 '11 at 01:22
  • 2
    Use a database to store the session info and just use a key in the session to map to the database row. That's how CodeIgniter does it if you turn on db session storage. – Endophage Aug 04 '11 at 01:24

2 Answers2

0

Sessions don't actually have a limit, but php does have a maximum memory it can use. Change this in the php.ini file like so:

memory_limit = 16M is changed to for example memory_limit = 32M or more if you so desire.

However i would advice to rethink the use of sessions for that amount of data.. Client certainly is king, but you don't have to play dumb and make bad code if they ask you to :).

Manuel
  • 10,153
  • 5
  • 41
  • 60
0

Well, the easy way to get around this is to store the data in a "temp" table in the database. Keep the ID of the row in the session. Then move the row over to the real table at the appropriate time.

My question is, "Is this a client request or a client requirement?" Because, realistically, you should be discouraging the client from interfering with the internals of the site as much as possible.

cwallenpoole
  • 79,954
  • 26
  • 128
  • 166