What is the alternative to PHP session variables?

I am writing a completely new website, and I would like to make sure that it scales easily if I ever get to the place where I have to host the site on several machines with load balancer.

Website user can be authenticated. In other words, I need to save some status information. My first reflex was to use Session variables, but then I will limit myself to one machine. I know that there are ways to store session variables externally (in the database, redis, memcached), but are these the only options?

What is the alternative to a session variable? How do Facebook and other major websites do this?

PS I'm not looking for another session handler (DB, redis, etc.). I would like to know if there is a way to completely get rid of session variables.

+4
source share
2 answers

Ever heard of session_set_save_handler ? It allows you to use mechanisms other than the default PHP session handler (the one that writes sess_xxxxxxxxxxxx files to the tmp directory).

You can write your own session handler that uses the database. This can be a time consuming task; therefore, you can stick with the default PHP session handlers for a while and transparently switch to the database when you are ready. You probably won't have to rewrite any code other than embedding and connecting your version of the six session processing functions.

+8
source

You can look into caching, i.e. using the Zend cache or APC cache , for example.

+1
source

Source: https://habr.com/ru/post/1395236/


All Articles