PhpRedis storage Session

Source: Internet
Author: User
Tags php redis
: This article mainly introduces the phpRedis storage Session. if you are interested in the PHP Tutorial, refer to it. More please support: http://www.webyang.net/Html/web/article_180.html

Redis is a high-performance key-value database. The emergence of redis can play a good complementary role in relational databases in some cases. On the other hand, many users choose redis for session storage. It makes up for the speed and benefits of file storage to achieve a higher availability.

Modify php. ini settings

 
 
  1. session.save_handler = redis
  2. session.save_path ="tcp://127.0.0.1:6379"
After modification, restart php-fpm. phpinfo () can view that the session is stored in redis.
If you do not want to modify php. ini, add the following to the code:
 
 
  1. ini_set("session.save_handler","redis");
  2. ini_set("session.save_path","tcp://127.0.0.1:6379");
If the connection password ( RequirePass), the save_path of the session needs to be modified to: tcp: // 127.0.0.1: 6379? Auth = RequireThe value of pass.
If you select redis database, session. save_path = "tcp: // xx. xx: 6789? Database = 11 ", and so on.
View the redis stored session value:
 
 
  1. Session_start ();
  2. $ _ SESSION ['sessionid'] = 'www .webyang.net ';
  3. $ Redis = new redis ();
  4. $ Redis-> connect ('2017. 0.0.1 ', 127 );
  5. // Redis uses PHPREDIS_SESSION: adds session_id as the key and stores it as a string
  6. Echo $ redis-> get ('phpredis _ SESSION: '. session_id (); // output www.webyang.net
  7. ?>

On the Internet, we can see that there is a question about the concurrency consistency of the redis stored session value (the file storage session has a file lock for processing). This is not studied.
Install the redis service and php redis extension in linux: www.webyang.net/Html/web/article_174.html


The above introduces the php Redis storage Session, including The require content, hope to be helpful to friends who are interested in the PHP Tutorial.

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.