Session: In a computer, especially in a network application, it is called "conversation control." So this article will share with you how to save session sessions to Redis, need to hurry to learn it.
PHP session sessions are saved as files by default in the session cache directory of the PHP.ini profile settings, and the file save session is inefficient when each user logs in once to generate a unique session_id file on the server when the user logs on to level hundreds of thousands of , there will be hundreds of thousands of files generated on the server, this time the disk's session Directory IO read and write will be very slow, causing the user to log on when the program will spend a lot of money on the session file read and write. When a large number of users log on with insufficient read and write ability, the resulting file is locked by the process of the first operation session, and other requests are blocked. The request hangs at Session_Start () until the session file is unlocked. This is the time to optimize the slow login problem.
Because the locked session file will not be unlocked until the end of the script execution or the session closes normally, in order to prevent a large number of PHP requests (need to use $_session data) to be locked, you can close the session immediately after writing, thus releasing the lock.
Open session session_start ();//write to $_session[' Is_login ']=1;//write to the session and then close the Write Session_write_close () of the previous conversation file;
PHP session sessions are written to Redis
When Redis data is stored in a computer memory bar, the computer's memory bar is sketched at dozens of times times the speed of the hard disk, so if you write the PHP session to the Redis cache, the speed will be much higher. Configuration method:
Mode one, the PHP script is set to change the way PHP session is written <?phpini_set ("Session.save_handler", "Redis"); Ini_set ("Session.save_path", "tcp://127.0.0.1:6379");//If there is a password Ini_set ("Session.save_path", "tcp://127.0.0.1:6379?") Auth=password ");? >
Modify PHP config file Php.inisession.save_handler = Redis Session.save_path = "tcp://127.0.0.1:6379"//If there is a password Session.save_path = "Tcp://127.0.0.1:6379?auth=password"