It is good to use Memcache to synchronize sessions, of course, you can also save the session via Redis, which allows PHP to open and store the session in the Redis cache. The following is a procedure for setting up a session with Memcache in a Web cluster:
1. Simulating a Web cluster
I started two memcached processes, simulating two servers separately.
/usr/local/bin/memcached-d-M 20-u zhangy-p 12000-p./memcached.pid
/usr/local/bin/memcached-d-M 20-u zhangy-p 13000-p./mem.pid
2, modify the configuration of PHP
Vi/usr/local/php/lib/php.ini
Session.save_handler = "Memcache"
Memcache.hash_strategy = "consistent"
Session.save_path = "tcp://127.0.0.1:13000?weight=10,tcp://127.0.0.1:12000"
Note: The first line, the session storage method is memcache; the second line, Memcache hash algorithm is consistent; third row, session storage status;
3. Restart Apache
View Phpinfo
Session
| Session Support |
Enabled |
| Registered Save handlers |
Files User SQLite Memcache |
| Registered serializer Handlers |
PHP php_binary |
Immediately following are:
| Session.save_path |
tcp://127.0.0.1:13000,tcp://127.0.0.1:12000 |
tcp://127.0.0.1:13000,tcp://127.0.0.1:12000 |
4, do a simple test as follows:
A), Prepare documents session.php
<?php session_start (); $_session[' username '] = "ABCABC"; Echo session_id ();?>
b), display session content file
<?php $mem = new Memcache; $mem->addserver ("127.0.0.1", 12000) or Die ("Could not add server 12000"); $mem->addserver ("127.0.0.1", 13000) or Die ("Could not add server 13000"); $val = $mem->get (' Qp0mrob2ovcqle3u4lbr4obsa5 '); Echo session_id (); The resulting session Idecho $val;?>
http://www.bkjia.com/PHPjc/824607.html www.bkjia.com true http://www.bkjia.com/PHPjc/824607.html techarticle using the Memcache to synchronize the session is still good, of course, can also be used to save the session via Redis, PHP can be opened and stored in the session to the Redis cache, the following is set to use Memcache in W ...