Example of setting regular session cleaning in PHP-PHP source code

Source: Internet
Author: User
Tags config php
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. 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.

Script ec (2); script

After php is configured, the default php will generate the session to the/tmp directory, resulting in a large number of files in the/tmp directory. Therefore, you need to regularly clean up the session:

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;
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 at: 2014-03-31'>/var/spool/cron/root
[Root @ hz scripts] # echo '0 3 ** 0/bin/bash/byrd/scripts/spehspsion. sh>/dev/null 2> & 1'>/var/spool/cron/root


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

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.