1: See how seesion supports storage in the current PHP version
You can see that the current session supports storage methods in the following ways:
Files: File mode, PHP default storage method, put the stored value in the server's designated directory
User: Users mode, temporarily do not understand
Redis: Supports Redis storage. From the diagram above, you can see that the current session is a Redis store, and the connection information is specified
Memcache: Supports Memcache storage
2:redis|memcache Storage Configuration method (support Redis|memcache expansion)
One: PHP.ini configuration (recommended)
Session.save_handler = [Redis|memcache]
Specifies the address of the connection Redis|memcache, with multiple configurations separated by ",". For Redis, if you have a password append auth=[password], append database=[num If you want to specify a database slice for Redis storage]
Session.save_path = "Tcp://2.2.2.230:6379?auth=123456&database=16"
Two: Configuration in the program
Ini_set ("Session.save_handler", "Redis");
Ini_set ("Session.save_path", "tcp://2.2.2.230:6379?auth=123456");
3:session optimization
Since the default session is stored through files stored in the server file, so it will generate IO operations, large traffic session will affect the session read, it is recommended in the actual production environment, the use of Redis|memcache for storage , they are all memory-based storage, most notably reduced IO operations
4: Actual operation
The change of Session storage mode is the same as the default operation session. Note that when you do the session, be sure to add session_start (), which is equivalent to instantiating the session object, because the default session is closed, which is an empty object . Individuals in the simple test of redis, because there is no open session_start, resulting in the normal session can not be accessed, usually with the framework, to really did not notice this place.
Session storage optimization in PHP