Session expiration time in php

Source: Internet
Author: User
Many people have encountered that PHP sessions always don't expire. as the browser process goes, here is a brief introduction. Many people have encountered that PHP sessions always don't expire. as the browser process goes, here is a brief introduction:

In PHP, set php. ini and find session. gc_maxlifetime = 1440 (PHP5 is 24 seconds by default)

You can set the expiration time as needed, but some people say that it does not work after the setting!

In fact, it is not ineffective, but because the system default:

Session. gc_probability = 1
Session. gc_divisor = 1000

That is to say, the garbage collection has a probability that 1/1000 means that the session is recycled once for 1000 times.

As long as you have a large access volume, you can achieve recovery. Otherwise, you can set the value of session. gc_divisor,

For example: session. gc_divisor = 1, so that you can see the effect of SESSION expiration.

Or you can change your mind to solve the problem of session expiration.

For example:

Use the session to record the time, and check whether the time you want to keep has been exceeded for the first access,

After the expiration time is exceeded, you can manually cancel the session. This can also be used to set the session expiration time. Many people have encountered that PHP sessions always don't expire. as the browser process goes, here is a brief introduction:

In PHP, set php. ini and find session. gc_maxlifetime = 1440 (PHP5 is 24 seconds by default)

You can set the expiration time as needed, but some people say that it does not work after the setting!

In fact, it is not ineffective, but because the system default:

Session. gc_probability = 1
Session. gc_divisor = 1000

That is to say, the garbage collection has a probability that 1/1000 means that the session is recycled once for 1000 times.

As long as you have a large access volume, you can achieve recovery. Otherwise, you can set the value of session. gc_divisor,

For example: session. gc_divisor = 1, so that you can see the effect of SESSION expiration.

Or you can change your mind to solve the problem of session expiration.

For example:

Use the session to record the time, and check whether the time you want to keep has been exceeded for the first access,

After the expiration time is exceeded, you can manually cancel the session. This can also be used to set the session expiration time.

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.