We’ve reached the point that it’s time to start adding more machines to serve our Yii-driven site and as such we will be using shared session management hitting a dedicated memcached server with a fallback to a mysql server. Unfortunately I’m having a tough time finding any articles on this using the Yii framework. Would it be better to deal with this at the lower level (i.e., session_set_save_handler)?
Did you get any joy with this? I am battling to use memcache do what I want - I want to write cache items from one machine and read from another and this just doesnt seem to work the way I would think it should (using a shared cache).
To be honest I’m extremely surprised at the lack of comments on this thread. I don’t know if it’s because people do this at the save_session_handler() layer, or because they prefer sticky sessions to shared sessions, or simply because nobody has reached the point of scaling their app to multiple machines with Yii.
At the moment we’re using sticky sessions. Unless we can find actual example implementations of session management using cache+db fallback with the Yii framework, we will probably just override php’s save_session_handler.
I have posted a separate message. It seems with Elasticache (which is what you would use for what you wanted in the Amazon environment) the cache items are specific to the process that created them. I cant help feeling that this should be configurable!
I am wrong!! This is a yii specific thing and is easily fixable.
Yii creates a unique cache item ID using an application id that it generates and the item key. You can easily override the application key and then these cross process things will work fine. This drove me nuts for weeks - eventually I had to look at the yii code to figure it out.
In your config add the following :
in the same array as
and you will be able to access items created by one machine on another.