Summary of the session method for storing memcache in php

Source: Internet
Author: User
Php uses memcache to store the session method Summary set the session uses memcache to store the method I: in php. set the session globally in ini. save_handlermemcachesession.save_pathtcp: 127.0.0.1: 11211 Method II: Under a directory. htaccessphp _ php use memcache to store the session method summary

Set the session to use memcache for storage

Method I: global settings in php. ini
Session. save_handler = memcache
Session. save_path = "tcp: // fig: 11211"


Method II:. htaccess under a directory
Php_value session. save_handler "memcache"
Php_value session. save_path "tcp: // fig: 11211"


Method III: or in an application

1 ini_set("session.save_handler", "memcache"); 2 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 ".

If the installed PECL is memcached (the extension dependent on the libmemcached Library), the configuration should be
Add Php code to favorites
Ini_set ("session. save_handler", "memcached"); // it indicates that memcached is not memcache.
Ini_set ("session. save_path", "127.0.0.1: 11211"); // do not use tcp: [/B]


Code example (not dependent on the libmemcached Library)

 1 
 
"; 11 print $_SESSION['TEST3']; 12 print "

"; 13 print session_id(); 14 ?>

Use sessionid to query in memcached:

?

1

2

3

4

5

6

$memcache = memcache_connect('localhost', 11211);

var_dump($memcache->get('19216821213c65cedec65b0883238c278eeb573e077'));

$memcache->set('aaaa', 'hello everyone');

var_dump($memcache->get('aaaa'));

?>

You will see
String (37) "TEST | I: 1177556731; TEST3 | I: 1177556881 ;"
This output proves that the session works normally.

Related Article

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.