Three configuration methods for using Memcache storage session in PHP

Source: Internet
Author: User
Tags session id php file

  The following is a simple PHP project distributed deployment, a session of the synchronization scheme, using Memcache to store the session. and summed up three kinds of configuration methods, need friends can refer to the next

  1, directly modify the php.ini configuration file   code as follows: Session.save_handler = memcache//Set session storage mode for memcache  Memcache.hash_ Strategy = "consistent"//set Memcache hash algorithm   Session.save_path = "tcp://127.0.0.100:11211"//Set session storage location, Multiple memcache are separated by commas, such as:tcp://127.0.0.1:11211,tcp://127.0.0.1:12000    2, using the. htaccess file configuration   code below in the directory: 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 more, also do not recommend this approach.     3, modify the configuration in the project's PHP file   copy code code as follows: Ini_set ("Session.save_handler", "Memcache");  Ini_set (" Session.save_path "," tcp://127.0.0.100:11211 ");   4, test example     code as follows://test session read is normal   session_start ();  $_session[' username '] = "jb51.net";   Echo session_id ();   //read from Memcache session  $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 ");   //session_id Access data    //Ben  //$session = $m->get (session_id ()); session_id:d527b6f983bd5e941f9fff318a31206b   //Another server, known session id  $session = $m->get (" d527b6f983bd5e941f9fff318a31206b ");    echo $session." <br/> "; Will get the data: username|s:16: "Pandao"; the corresponding value can be obtained by parsing the   echo session_id (). <br/> ";  exit;        above just a few simple instructions, in fact, said Han off, generally speaking, do distributed, that must have server permissions, so recommend the first."

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.