How PHP session is stored to Redis _php tips

Source: Internet
Author: User
Tags php session redis

Of course, to write the first installation of PHP extensions, can refer to this article: Redis and PHP Extended installation
Modify the php.ini settings

Copy Code code as follows:

Session.save_handler = Redis
Session.save_path = "Tcp://127.0.0.1:6379″
Reboot php-fpm or Nginx,phpinfo () after modification

Session Redis
If you don't want to modify php.ini,

Copy Code code as follows:

Ini_set ("Session.save_handler", "Redis");
Ini_set ("Session.save_path", "Tcp://127.0.0.1:6379″");

If the configuration file/etc/redis.conf set the connection password Requirepass save session will be an error, Save_path this write tcp://127.0.0.1:6379?auth=authpwd can.
Some netizens mentioned that the Session,redis of file storage or Memcache storage session value will have concurrency consistency problem, this piece has not been carefully measured.
Copy Code code as follows:

<?php
If not modified php.ini the following two lines of comments are removed
Ini_set (' Session.save_handler ', ' Redis ');
Ini_set (' Session.save_path ', ' tcp://127.0.0.1:6379 ');
Session_Start ();
$_session[' sessionid '] = ' This are session content! ';
echo $_session[' SessionID '];
Echo ' <br/> ';

$redis = new Redis ();
$redis->connect (' 127.0.0.1 ', 6379);
Redis with session_id as key and is stored as string
echo $redis->get (' phpredis_session: '. session_id ());
?>

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.