PHP Save session with Redis

Source: Internet
Author: User
Tags fpm

1. Modify the session configuration in php.ini:

  ini_ Set ( ' Session.save_handler ' ,  ' Redis ' ); 
ini_set ( ' Session.save_path ' , ' tcp://192.168.1.10:6379 ' //redis have password words
//ini_set (' Session.save_path ', ' tcp://192.168.1.10:6379? Auth=password ');

Note: The configuration in php-fpm.conf overrides the configuration in php.ini, so make sure that the corresponding configuration in PHP-FPM is turned off or modified:


   2. Using session in code:                     

<?php/* * can be configured with the following options *session.auto_start = 1                -auto start, do not need session_start () *session.cookie_lifetime = 31536000-- The session_id of cookies expires one year, the default is 0, and closing the browser expires. *session.gc_maxlifetime = 1447--session payback time, default 1447, the expire of the session stored in Redis is set to this entry. */session_start (); Session.auto_start = 1 can be configured to turn on automatically. $_session[' foo '] = ' bar '; Echo $_session[' foo '];   Bar, the current session already exists in Redis//redis is stored in string type Session$redis = new Redis (); $redis->connect (' Localhsot ', 6379); echo $redis->get (' phpredis_session: '. session_id ());//Format: string "uid|i:554:" "; Username|s:5:" Hello ";"

PHP Save session with Redis

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.