Memcache Storing PHP session

Source: Internet
Author: User
Memcache Storing PHP session

1. Modify the configuration file and set the global settings in php.ini:

Session.save_handler = Memcachesession.save_path = "tcp://127.0.0.1:11211"
Or a. htaccess in a directory:
Php_value Session.save_handler "Memcache" Php_value session.save_path  "tcp://127.0.0.1:11211"
Or in one application:
Ini_set ("Session.save_handler", "memcache"); Ini_set ("Session.save_path", "tcp://127.0.0.1:11211");?

Use multiple memcached servers separated by commas "," and, as described in the memcache::addserver () documentation, can take additional parameters "persistent", "weight", "timeout", "Retry_ Interval "And so on, like this:" Tcp://host1:port1?persistent=1&weight=2,tcp://host2:port2 ".


5. Use Memcache for session storage in the program, and test it with an example:

 
  Connect (' 127.0.0.1 ', 11211); $var = $memcache _obj->get (session_id ()); Echo $var;? >
will have to see
Array ([Joo] = hello~) joo|s:6: "hello~";

This output proves that the session is working properly.

Using Memcache to store sessions can be much faster than files when reading and writing, and it is convenient to have multiple servers sharing sessions, which are configured to use the same set of memcached servers, reducing the additional effort.
The disadvantage is that the session data are stored in memory, the persistence of the lack of, but the session data is not a big problem.

1/F Jimmyyem 2012-02-15

I really win the following test, I installed the memcache, not memcached, I am in php.ini and procedures to change 2 kinds have tried, found not yet
Give me a hint

  • 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.