Session storage optimization in PHP

Source: Internet
Author: User

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

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.