PHP Session storage Mode

Source: Internet
Author: User

File:

Session.save_handler = Filessession.save_path = "/tmp"

Session file synchronization


Memcache

Session.save_handler = Memcachesession.save_path = "Tcp://127.0.0.1:11211,tcp://mem server 2: Port number ..." Using multiple memcached server When separated by a comma "," You can take additional parameters such as "persistent", "weight", "timeout", "Retry_interval" and so on, similar to: "tcp://host1:port1?persistent=1& Weight=2,tcp://host2:port2 "Reference: http://php.net/manual/zh/memcache.addserver.php if the pecl installed is memcached ( Using the Libmemcache Library), the configuration should be Ini_set ("Session.save_handler", "memcached"); is memcached not Memcacheini_set ("Session.save_path", "127.0.0.1:11211"); Do not tcp://parameter reference: http://php.net/manual/zh/memcached.addserver.php

Parameter reference:
http://php.net/manual/zh/memcache.addserver.php
http://php.net/manual/zh/memcached.addserver.php



Redis

Session.save_handler = Redissession.save_path = "Tcp://host1:6379?weight=1, tcp://host2:6379?weight=2&timeout= 2.5, tcp://host3:6379?weight=2 "parameter: Weight specific gravity timeout Timeout persistent persistent connection value 0 1prefix session ID prefix auth Validate database selected databases Sessi On in seconds indicates that the life cycle is controlled by the Session.gc_maxlifetime ini_set (' session.gc_maxlifetime ', ' 3600 ') can change the time to live, need Setex command, Redis version at least 2.0phpredis can also be linked to a UNIX domain socket:unix:///var/run/redis/redis.sock?persistent=1&weight=1& Database=0
Parameter reference: Https://github.com/phpredis/phpredis, http://blog.csdn.net/fb408487792/article/details/43274565


The pros and cons of several ways are obvious: using Redis is recommended


Redis instance:

Ini_set (' Session.save_handler ', ' Redis '); Ini_set (' Session.save_path ', ' tcp://127.0.0.1:6379 '); Session_Start (); $_ session[' sessionkey '] = ' redis session! '; Var_dump ($_session[' SessionKey '); Echo ' <br/> ';        $redis = new Redis (), $redis->connect (' 127.0.0.1 ', 6379),//redis with session_id as key and is stored in string form var_dump ($redis- >get (' phpredis_session: '. session_id ()));


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

PHP Session storage Mode

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.