The following is a simple PHP project distributed deployment, session synchronization of one of the scenarios, using Memcache to store the session. And summed up three ways to configure, the need for friends can refer to the following
1, directly modify the php.ini configuration file
The code is as follows:
Session.save_handler = memcache//Set session is stored in Memcache
Memcache.hash_strategy = "consistent"//set Memcache hash algorithm
Session.save_path = "tcp://127.0.0.100:11211"//Set Session storage location, multiple memcache separated by commas, for example: tcp://127.0.0.1:11211,tcp:// 127.0.0.1:12000
2. Use the. htaccess file configuration under the directory
The code is as follows:
Php_value Session.save_handler "Memcache"
Php_value Session.save_path "tcp://127.0.0.1:11211"
Description: This is only for Apache, the current use of nginx is more, it is not recommended this way.
3. Modify the configuration in the PHP file of the project
Copy the code code as follows: Ini_set ("Session.save_handler", "memcache");
Ini_set ("Session.save_path", "tcp://127.0.0.100:11211");
4. Test examples
The code is as follows:
Test session Read is normal
Session_Start ();
$_session[' username '] = "jb51.net";
Echo session_id ();
Read the session from the Memcache
$m = new Memcache ();
$m->connect (' localhost ', 11211);
Or so
$mem->addserver ("127.0.0.1", 11211) or Die ("Can ' t add Memcache server 127.0.0.1:12000");
Get data based on session_id
Natively
$session = $m->get (session_id ()); session_id:d527b6f983bd5e941f9fff318a31206b
Another server, known as session ID
$session = $m->get ("d527b6f983bd5e941f9fff318a31206b");
echo $session. "
"; Will get the data: username|s:16: "Pandao", and parse it to get the corresponding value
Echo session_id (). "
";
Exit
Above is just some simple explanation, actually said humorous digression, generally, do distributed, that certainly has the server permission, so recommend the first kind.
http://www.bkjia.com/PHPjc/750260.html www.bkjia.com true http://www.bkjia.com/PHPjc/750260.html techarticle The following is a simple PHP project distributed deployment, session synchronization of one of the scenarios, using Memcache to store the session. and summed up three kinds of configuration methods, the need for friends can refer to the following ...