Home >Backend Development >PHP Tutorial >How to set up php to automatically clean the session regularly

How to set up php to automatically clean the session regularly

墨辰丷
墨辰丷Original
2018-06-06 10:10:431542browse

This article mainly introduces how to set up PHP to realize regular automatic cleaning of sessions. Interested friends can refer to it. I hope it will be helpful to everyone.

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 


定时任务: 
[root@hz scripts]# echo '#This is a config php session BY:BYRD AT:2015-11-12' >>/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

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

PHP file download Chinese file name garbled

Common sorting algorithm in php

Three methods for PHP to determine whether a mobile phone is IOS or Android

The above is the detailed content of How to set up php to automatically clean the session regularly. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn