PHP, write session data to unused storage media

Source: Internet
Author: User

First of all, my siession data can be written to: the session data area or database in the file,

Then how to write the session data in the file or the data area of the session data into the database, or arbitrarily select two different media to write each other,

So the memory mechanism of the session is rewritten.

Objective:

① easy to manage a large number of session data

② facilitates the Web server cluster (that is, multiple Apache servers, because one may not be enough) to share session data. (There can actually be a server dedicated to storing session data, and then there are multiple Web servers, so that multiple Web servers share the concept of the unit session data)

Scheme:

Storage, such as memory,

The following is an experiment with the mechanism of warehousing:

① implementation process: ① defines (implements) storage-related functions. , and then set it to the function that the session mechanism needs to store (in fact, just like the idea of the auto-load function, it tells PHP to use my own definition of this function as my session store function)

Session mechanism, a total of 6 storage functions required

      

(This order can be disrupted)

The USERSESSIONGC () is a garbage collection function, which is the function that manages those temporary files (data areas).

The stored function of the Session is set by the PHP Session_set_save_handler (start processor, end processor, read processor, write processor, delete processor, garbage collector) function to complete

So that's what it looks like:

        

(This order cannot be disrupted)

Then, I introduce the file that sets the storage mechanism in my session file:

                

Be sure to ensure that the session base is open before opening it:

                

PHP, write session data to unused storage media

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.