Quantcast
Channel: budiwijaya.net » quick-tips
Viewing all articles
Browse latest Browse all 11

Tips to delete sessions file of php in CentOS 5.5

$
0
0

Different from Ubuntu, in CentOS 5.5, I do not find a mechanism to delete files from the php session. Because I’m worried the sessions file is not deleted, I import the fileremoval mechanism of Ubuntu.

I copy the following files from Ubuntu.

$cat /usr/lib64/php/maxlifetime

#!/bin/sh -e
max=1440
for ini in /etc/php.ini; do
cur=$(sed -n -e ‘s/^[[:space:]]*session.gc_maxlifetime[[:space:]]*=[[:space:]]*\([0-9]\+\).*$/\1/p’ $ini 2>/dev/null || true);
[ -z "$cur" ] && cur=0
[ "$cur" -gt "$max" ] && max=$cur
done
echo $(($max/60))
exit 0

Then we create cron file to auto delete the sessions files.

$cat /etc/cron.d/php

# /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/lib64/php/maxlifetime ] && [ -d /var/lib/php/session ] && find /var/lib/php/session -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib64/php/maxlifetime) -delete

That’s it.

centos php session files, /var/lib/php/session, php centos session, linux var lib php session, linux delete php session files, linux /var/lib/php/session clean session files, howto clear sess_ in centos, how to remove sessions on centos, how to remove sessions file in /var/lib/php/session automatically, how to purge php centos

Viewing all articles
Browse latest Browse all 11

Trending Articles