This time to bring you the PHP set Web cluster session synchronization steps in detail, PHP set Web cluster session synchronization of the note what, the following is the actual case, together to see.
The default session for PHP is file storage:
Session.save_handler = Filessession.save_path = "/var/lib/php/session"
As a Web cluster, when session synchronization is required, it is a good idea to save the session to a distributed memcache to achieve shared synchronization.
Method:
The 1th type:
Vi/etc/php.ini
Session.save_handler = Memcachesession.save_path = "tcp://192.168.20.193:11211,tcp://192.168.20.194:11211"
The 2nd type:
Configured in PHP files using the Ini_set function for virtual hosts that cannot modify configuration files
<?php....ini_set ("Session.save_handler", "memcache"); Ini_set ("Session.save_path", "tcp://192.168.20.193:11211 , tcp://192.168.20.194:11211 "); >
Restarting the Web server
Service httpd Restart
View Phpinfo
Test
The login.php in 192.168.20.193
<?phpsession_start (); $_session[' login_time '] = time (); $_session[' username '] = ' test2 '; $token =session_id (); echo $ Token;//memache implementation $mem = new Memcache (), $mem->addserver (' 192.168.20.193 ', 11211); $mem->addserver (' 192.168.20.194 ', 11211);/*//memached implements $MEM = new Memcached (); $servers = Array (' 192.168.20.193 ', 11211, '), array (' 192.168.20.194 ', 11211, 67)); $mem->addservers ($servers); */echo '
The user.php in 192.168.20.194
<?php$mem = new Memcache (), $mem->addserver (' 192.168.20.193 ', 11211), $mem->addserver (' 192.168.20.194 ', 11211); $token =$_get[' token '];//get the Tokenprint_r ($mem->get ($token)); ><p><a href= "http://192.168.20.193/user.php?token=<?php echo $token;? > "rel=" External nofollow "target=" _balnk "> Return to 193 site's personal hub </a></p>
Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!
Recommended reading:
PHP+MONGODB database Operation steps
PHP closed case analysis of the use of practical cases