-2

I am working on a large web application which need the database to be retrieved from session instead of database. For first time I am retrieving it from db and saving to session but for onward calls of data I am going to session.

It is handling the data perfectly but at a stage when I got some more data to be stored in session then it session got destroyed automatically...

"This problem seems to similar to those question which says title as Session destroyed after redirect to other pages of site."

I got the answer for those questions but my point here is how handle this thing when we know in future I have more data to be stored inside session,

I wanted to know little bit more involved answer for this as right now we are in development stage but on production when have user say 100000 or more then how session will behave, does application behave in the same manner like it did before.

Kindly discuss this with me, I am even researching, need corporation for some more technical in php as this discussion may help as a solution to many of people who are facing the same kind of issues..

Cœur
  • 32,421
  • 21
  • 173
  • 232
Rahul Thakral
  • 17
  • 1
  • 7
  • 3
    You really shouldn't treat session as a cache, sessions are meant for persisting state not for caching data. – hidden_4003 Mar 28 '17 at 12:22
  • You can keep a key/id in the session and store the data in a database which you can fetch by that key? – maesbn Mar 28 '17 at 12:23
  • 1
    Instead of session, you can make use of memcached for storing the data – Saili Jaguste Mar 28 '17 at 12:26
  • More info on when to use sessions http://stackoverflow.com/questions/361245/caching-variables-in-the-session-variable and http://stackoverflow.com/questions/9402028/cache-or-store-in-session – qwertzman Mar 28 '17 at 12:47
  • See if this answer helps you: http://stackoverflow.com/questions/17554990/session-variables-how-much-data-is-too-much – Murilo Mar 28 '17 at 13:04
  • @hidden_4003 Correct But my point is little bit different. Let me explain.. I need to load the page and my page contains a search form, even my site is 90% dependent of search form and that search form have more then 100's Fields to select and those fields we have to retrieve from database and each data have thousands of rows.. I don't want to retrieve it from database all the time, although I have not used page cache yet, to store the data. Does using page cache help me in this case.. – Rahul Thakral Mar 28 '17 at 14:05
  • @SailiJaguste Will follow your suggestion but my point is, can it handle a large amount of data..?? I have not Used it yet in any version of CI.. can you explain little bit more about it... – Rahul Thakral Mar 28 '17 at 14:07
  • By the way.. thanks everyone for discussing the things here with me. – Rahul Thakral Mar 28 '17 at 14:08
  • @RahulThakral session is usually locked during the request so you will inevitably run into concurrency problems, that is why it is advisable not to use session as a cache, use memcached, only have cache key in the session. – hidden_4003 Mar 30 '17 at 10:10
  • @hidden_4003 appriciated your reply, I am looking after memcached.. lets see how it works for my application. Thanks Alot.. – Rahul Thakral Mar 30 '17 at 18:03

1 Answers1

-1

You need to use native PHP session because PHP session stores only id in the cookie. But codeigniter stores all the data in the cookie and this is the problem where you are stuck.

So either you need to use native PHP sessions in codeigniter or you can use a library. Here is the link for a library whose syntax is sam as CI:

Github Thread by Derek Jones

ram kumar
  • 104
  • 6
  • Thanks for Reply.. But my point is, is it good to overwrite whatever is written in core files... I think no..there must be something we can handle it in some another way.. or if it is a leak in CI then I must say we should try this.. But also is there any condition where php native session got crashed due to much large amount of data.. – Rahul Thakral Mar 28 '17 at 14:10
  • yes you shouldn't overwrite it. If you want to go safely you can maintain database tables for sessions in CI. – ram kumar Mar 28 '17 at 14:12
  • I did maintaining the session inside database table but it hard to manage the session.. as the development of application increases the load of data, then again things of session destroying automatically starts happening.. 4 months before I reduced the load of data that I can and now in between 4 months I have added few more things in session to maintain some state functionality of users but it sends me again to research on the things of development that I did 4 months before.. – Rahul Thakral Mar 28 '17 at 14:41