I am storing a lot of variables in session, which is creating a performance problem.
So, I have been asked to store it somewhere else, I can store it in the database, but that would again be slow.
Is there any better alternative to store session variables?
Global variable are per file/request. While cookies will open the variables to users and will not keep it server side.
Thanks in advance for your answers!
Consider
memcachedfor semi-persistent data like this. Store the cache key in$_SESSIONand then use it to grab your cached data.Since
memcachedcaches everything in memory (and is strictly a key-value store), it’s faster than a database. It’s somewhat ideal for things like sessions, because if you happen to lose the cached data, nothing serious is lost (the user just gets unexpectedly logged out).In fact, the PHP Memcache implementation provides a session handler (see Example #2) which could transparently handle your sessions for you without you really needing to make any modifications to your code.