Confixx PHP Sessions

Aus MHC-Wiki

Wechseln zu: Navigation, Suche

Die PHP Sessions werden mit den Standard-Cron-Sctipten (zumindest unter Debian) nicht gelöscht, wenn man Confixx verwendet. Ich mache das mit folgendem Script:

/usr/local/bin/delphpsess.sh

#!/bin/bash

[ ! -x /usr/lib/php5/maxlifetime ] && exit 0
[ ! -d /var/lib/php5 ] && exit 0

for i in `ls -1 /var/www | grep ^web[0-9]`
do
        find /var/www/$i/phptmp -name "sess_*" -type f -cmin +$(/usr/lib/php5/maxlifetime) -print0 | xargs -n 200 -r -0 rm
done

Executable setzen nicht vergessen:

chmod +x /usr/local/bin/delphpsess.sh

Der Croneintrag muss noch entsprechend geändert werden:

/usr/local/bin# cat /etc/cron.d/php5

# /etc/cron.d/php5: crontab fragment for php5
#  This purges session files older than X, where X is defined in seconds
#  as the largest value of session.gc_maxlifetime from all your php.ini
#  files, or 24 minutes if not defined.  See /usr/lib/php5/maxlifetime

# Look for and purge old sessions every 30 minutes
# 09,39 *     * * *     root   [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -type f -cmin +$(/usr/lib/php5/maxlifetime) -print0 | xargs -n 200 -r -0 rm

09,39 *     * * *     root   /usr/local/bin/delphpsess.sh

Wenn sich zu viele Dateien angesammelt haben dann kann ggf. folgendes Löschscript helfen:

#!/bin/bash

[ ! -x /usr/lib/php5/maxlifetime ] && exit 0
[ ! -d /var/lib/php5 ] && exit 0

for i in `ls -1 /var/www | grep ^web[0-9]`
do
       find /var/www/$i/phptmp -name "sess_*" -type f -cmin +$(/usr/lib/php5/maxlifetime) | wc -l
       for j in `find /var/www/$i/phptmp -name "sess_*" -type f -cmin +$(/usr/lib/php5/maxlifetime)`
       do
              rm $j
       done
done
Persönliche Werkzeuge
Navigation