PhpSessiongc mechanism is different from untu in window.

Source: Internet
Author: User
PhpSessiongc mechanism is different from untu in window. I have benefited a lot from seeing the previous Mr_jing session article. I also encountered a session problem in win. He mentioned the last interesting thing in the article. at that time, I felt that it was too TMD (sweet) fate. Then I made up an article about the execution sequence mechanism of session_set_save_handler that I understood as a relatively watery diary. but I still don't want to be reconciled. let's see if the session in linux does not work, (Currently, Windows cannot ).

Test the session gc mechanism in win
  • First describe the environment-phpstudy under win
  • 2. php. ini configuration

    3. the code starts to write. php into the session. The value is the current timestamp.

       

    4. Read the session code.

      ";echo 'gc_probability'.ini_get('session.gc_probability')."
    ";echo 'gc_pisor'.ini_get('session.gc_pisor')."
    ";session_start();echo ''.'Session::=>';var_dump($_SESSION);echo ''.'Cookie::=>';var_dump($_COOKIE);echo '';echo "
    ReadTime".date('Y-m-d H:i:s',time());

    5. execute read. php
    The write time is 17:57:04.

    6. Read the session. you can see that the time and write time of the Read session value (the red elliptical circle above) are the same.
    17:57:04. Note that the row in readtime below is 13:58:56,

    Okay. Up to now, there has been no problem with win. Because even if the maximum survival time of your session (session. gc_maxlifetime) is 5 seconds, your gc ratio is, that is, recovery.
    Note:
    Gc collection starts from your session_start, and then runs open, read, and gc.
    For details, click here to view the session execution sequence.

    So even if a session has expired, you still have a value to read it, and the next time it is gc.
    (Some may think that the first time a user reads a value, it is inaccurate to determine whether the user is logged on. However, the real production environment is definitely not a single user, and there are many scenarios that trigger the session_start mechanism, that's not surprising .)

    That's a problem !!
    When we constantly refresh the read. php page on the win platform, the session value is always available. This is strange. it should be recycled. How can I keep getting it. In our understanding, session gc compares the last modification time of the file with the maxlifetime set in the current time and ini, and then triggers the recycle mechanism.

    Let's take a picture

    This is the wonderful place
    1. if you delete this session and write it directly, you will find that the creation time is the same as the creation time before the deletion. I can understand the same name, but is the same time swollen! Windows is too lazy to bring the recycle bin back? I cleared him.
    Attach a gif image (how boring I am ~, Open this image in IE browser, or Mito Xiuxiu, acdsee, and so on)

    Gc of session in linux

    Virtualbox created locally (lamp in ubuntu)
    Configuration example:

    Next, let's go to the dynamic graph: Display the write session, view the status of the session file, and then read it. The first read is a value, the stat sess ** file is still being viewed twice. After I refresh it once, the value is gone. It also verifies that the session process is open read (gc) write close. Note that the first time I have enabled a value, it is not the Read write value.

    Conclusion:
    The article was a bit rough and messy.
    Finally, I would like to thank you for your guidance, especially cfc4nx.

    Next time, make it clear ..

    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.