Search code examples
sessionrediscache-controlphp-5.6

sharing same php session acreoss different domains/servers using redis


We have one main domain and 4 sub domains running different instances and using same remote mysql database server. Some domains using PHP 5.6 and some using 5.5. we want to have our domains sharing the same PHP session, So that we can keep user data across these domains. I saw two methods Storing Sessions in a Database and using memcached. We are using redis on each servers.

Is it possible to set-up a centralised redis server to handle common php session across multiple servers


Solution

  • Yes it is possible. In PHP you can make your SessionHandler which will store you session data where you need. http://php.net/manual/en/session.customhandler.php

    phpredis library (https://github.com/phpredis/phpredis#php-session-handler) can do it for you.