Php session regular automatic cleanup method, phpsession cleanup _ PHP Tutorial

Source: Internet
Author: User
Tags config php
The php session is automatically cleared regularly. In php, the session is automatically cleared on a regular basis. in phpsession cleanup, I will introduce the example of setting the session regular automatic cleanup in PHP, the default value of session is to automatically clear the variables for the php session in 15 minutes.

Next, I will introduce you to the example of setting the PHP session to automatically clean up regularly, because the default session is to automatically clear the variables for 15 minutes, but some time does not take effect, let's take a look.

After php is configured, php will generate the session to the/tmp directory by default, resulting in a large number of files in the/tmp Directory. Therefore, the session needs to be cleaned regularly.

Modify php. ini:

[Root @ hz scripts] # grep "session. save_path = "/usr/local/php/lib/php. ini; session. save_path = "N;/path"; session. save_path = "N; MODE;/path"; session. save_path = "/tmp" session. save_path = "2;/tmp/session" [root @ hz ~] # Cat/byrd/script/Cleartmpsen. sh #! /Bin/bash # Version: 1.0 # Author: Byrd # Site: www.t4x.org # Contact: root # t4x.org # This is script will clear php session before 3 hours. I = "0 1 2 3 4 5 6 7 8 9 a B c d e f" for byrd in $ I; do for x in $ I; do mkdir-p/tmp/session/$ byrd/$ x; done chown-R bywww: bywww/tmp/session chmod-R 1777/tmp/session find/tmp/session-amin + 180-exec rm-rf {}\; if ['grep' session. save_path = '/usr/local/php/lib/php. ini | wc-l '-eq 3]; then sed-I's #; session. save_path = "/tmp" #; session. save_path = "/tmp" \ nsession. save_path = "2;/tmp/session" # g'/usr/local/php/lib/php. ini else exit 1 fi scheduled task: [root @ hz scripts] # echo '# This is a config php session BY: byrd: 2015-11-12 '>/var/spool/cron/root [root @ hz scripts] # echo '0 3 ** 0/bin/bash/byrd/scripts/speheat Sion. sh>/dev/null 2> & 1'>/var/spool/cron/root

Note: Because this configuration modifies php. ini, you need to restart the php process.

The above is all the content in this article. we hope you will gain some gains from this article.

In the following article, we will introduce you to the example of setting regular automatic session cleanup for PHP, because the default session is to automatically clear variables within 15 minutes...

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.