PHP - what is an alternative to session variables

I store many variables in the session, which creates a performance issue. So, I was asked to store it somewhere else, I can save it to the database, but it will be slow again.

Is there a better alternative to storing session variables? Global variable - for each file / request. Although cookies will open variables to users and will not support them on the server side.

Thanks in advance for your answers!

+4
source share
3 answers

Consider memcached for semi-persistent data like this. Save the cache key in $_SESSION , and then use it to capture cached data.

Since memcached caches everything in memory (and is strictly a key repository), it is faster than a database. This is somewhat ideal for things like sessions, because if you lose cached data, nothing serious is lost (the user just unexpectedly logged out).

In fact, the PHP implementation of Memcache provides a session handler (see Example # 2) that can transparently handle your sessions for you, without having to make any changes to your code.

+5
source

php sessions can be configured to work in many ways. you can run it from memcache if the server has enough free memory. it will be high performance

you can also use a database to store session information, but as you say, it can be slow.

Why are there currently performance issues? Is there a large number of sessions created or that large amounts of data are stored in the session?

+2
source

It depends on how many "many" variables? The default session store for rails uses cookies, which are usually enough for me. The cookie is encrypted if you are worried about exposing variables. Do you need to have a server side? With html5 you have localStorage options.

0
source

All Articles