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