Memcache stores phpsession

Source: Internet
Author: User
Memcache stores phpsession1. modify the configuration file and set session. save_handler = memcachesession. save_path = "tcp: // 127.0.0.1: 11211" globally in php. ini.

1. modify the configuration file and set it globally in php. ini:

session.save_handler = memcachesession.save_path = "tcp://127.0.0.1:11211"
Or. htaccess in a directory:
php_value session.save_handler "memcache"php_value session.save_path  "tcp://127.0.0.1:11211"
Or in an application:
ini_set("session.save_handler", "memcache");ini_set("session.save_path", "tcp://127.0.0.1:11211");?

Multiple memcached servers are separated by commas (,), which are the same as those described in the Memcache: addServer () document, you can include additional parameters such as "persistent", "weight", "timeout", and "retry_interval". for example, "tcp: // host1: port1? Persistent = 1 & weight = 2, tcp: // host2: port2 ".


5. use memcache in the program for session storage. use an example to test it:

 connect('127.0.0.1', 11211);$var = $memcache_obj->get(session_id());echo $var;?>
You will see
Array ( [joo] => hello~ ) joo|s:6:"hello~";

This output proves that the session works normally.

Using memcache to store sessions is much faster in reading and writing than when using files, and it is more convenient when multiple servers need to share sessions, you can configure these servers to use the same group of memcached servers, reducing the additional workload.
The disadvantage is that session data is stored in memory, which lacks persistence, but it is not a big problem for session data.

Jimmyyem on the first floor 2012-02-15 I actually tested it under win. I installed memcache, not memcached. I tried it in php. ini and in the program, but I found that I still cannot.
Give me some advice

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.