How will works sessions on Read/Write splitting infraestructure?


I need to deploy infraestructure which will have 1 master server and 1 slave server. I will use this method: but I wonder how it will work when saving the sessions. By default the sessions are stored as files on server ( ), but what if one request from the same user is on server1 and next request is on server2? Does it will be on data corruption/mismatch due to the session of the same user is saved in two different servers in a short lapse time?

Take in account that slave server and master server are able to receive reading requests since the web application is balanced and some reading requests are dispatched from master server and other requests are dispatched from slave server.


The database will handle the replication of data if you configure one as a master and one as a read only slave (within the dbms). In most cases this happens very quickly. With that in mind you can change your session store to use a database instead of the filesystem. With that configuration it will not matter which server serves the request.

I would personally recommend Redis to store your sessions. Yii has native support for it too. It it much faster than a SQL database and it is also very easy to share a single Redis server between several application servers. Session storage can put a strain on SQL databases.