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.