Memcache Storing PHP session

Source: Internet
Author: User
Memcache Storing PHP session

set session with Memcache to store ?

method I: Global settings in php.ini ?

PHP.ini code??

    1. Session.save_handler?=?memcache??
    2. Session.save_path?=? "tcp://127.0.0.1:11211"??


Method II: In a directory. htaccess ?

PHP.ini code??

    1. Php_value?session.save_handler? "Memcache"??
    2. Php_value?session.save_path?? "tcp://127.0.0.1:11211"??



Method III: Again or in one application ?

PHP code??

    1. Ini_set ("Session.save_handler",? "Memcache");??
    2. 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 ".?

If the installed pecl is memcached (the one that relies on the libmemcached library), then the configuration should be?

PHP code??

  1. ini_set ( " Session.save_handler ",? "memcached" );? //? memcached, not Memcach. E ??
  2. Ini_set ("Session.save_path",? "127.0.0.1:11211");? //? Do not tcp:[/b]??



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

PHP code??

  1. Session_Start ();??
  2. if? (!isset ($_session[' TEST ']))? {??
  3. ???? $_session [' TEST ']?=?time ();??
  4. }??
  5. ???
  6. $_session [' TEST3 ']?=?time ();??
  7. ???
  8. Print? $_session [' TEST '];??
  9. Print? "

    "
    ;??
  10. Print? $_session [' TEST3 '];??
  11. Print? "

    "
    ;??
  12. PRINT?SESSION_ID ();??
  13. ???


use SessionID to memcached to inquire about:?

PHP code??

  1. $memcache? =?memcache_connect (' localhost ',? 11211);??
  2. Var_dump ($memcache->get (' 19216821213c65cedec65b0883238c278eeb573e077 '));??
  3. $memcache->set (' aaaa ',?') Hello?everyone ');??
  4. Var_dump ($memcache->get (' aaaa '));??
  5. ???



Will see?
String (PNS) "test|i:1177556731; test3|i:1177556881; "?
This output proves that the session is working properly.

?

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