Set the session in PHP Memcache to store the method summary, sessionmemcache_php tutorial

Source: Internet
Author: User

Set the session in PHP to use Memcache to store the method summary, Sessionmemcache


Memcached provides a custom session processor that can be used to store user session data to the memcached server. A completely separate memcached instance will be used internally, so you can set up a different server pool if needed. The session key is stored under the prefix Memc.sess.key, so if you use the same server pool for the session and the usual cache, be aware of this. Another session and the usual reason for cache separation is that when the usual cache fills the memcached server, it may cause your session to be kicked out of the cache, causing the user to fall out of line.

Session.save_handler string

Set to memcached to turn on the memcached session processor.

Session.save_path string

Defines a comma-delimited Hostname:port-style session cache server pool, for example: "sess1:11211, sess2:11211".

Method I: Global settings in php.ini

Method II: In a directory. htaccess

Method III: Again or in one application

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

If the installed pecl is memcached (which relies on the extension of the libmemcached library), the configuration should be

Ini_set ("Session.save_handler", "memcached"); is memcached not memcache ini_set ("Session.save_path", "127.0.0.1:11211"); Don't tcp:[/b]

code example (the one that does not depend on the libmemcached library)

<?php session_start (); if (!isset ($_session[' test ')) {$_session[' test '] = time ();} $_session[' test '] = time (); Print $_session[' TEST ']; Print "

"; Print $_session[' TEST ']; Print "

Use SessionID to go to memcached to check:

<?php $memcache = memcache_connect (' localhost ',); Var_dump ($memcache->get (' Ccedecbceebe ')); $memcache->set (' aaaa ', ' hello everyone '); Var_dump ($memcache->get (' aaaa '));?>

'll see

String (PNS) "test|i:1177556731; test3|i:1177556881; "

This output proves that the session is working properly.

Here are two examples of usage to introduce PHP using memcached to store the session

One

Ini_set ("Session.save_handler", "Memcache"), Ini_set ("Session.save_path", "tcp://127.0.0.1:11211");

Multiple memcached

Ini_set ("Session.save_path", "tcp://127.0.0.1:11211,tcp://127.0.0.1:11211");

Two

Ini_set ("Session.save_handler", "memcached"); Ini_set ("Session.save_path", "...:");

Multiple memcached

Ini_set ("Session.save_path", "127.0.0.1:11211,127.0.0.1:11211");

Articles you may be interested in:

    • Using memcached to implement session mechanism in PHP to replace the native session support of PHP
    • Using Memcache to store session details based on PHP
    • PHP to put the session into the Memcached setting method
    • Three configuration methods for using Memcache storage session in PHP

http://www.bkjia.com/PHPjc/1091855.html www.bkjia.com true http://www.bkjia.com/PHPjc/1091855.html techarticle set the session in PHP using Memcache to store the method summary, Sessionmemcache memcached provides a custom session processor can be used to store the user session data to memcached service ...

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