Tag Archives: centos 5.5

Tips to delete sessions file of php in CentOS 5.5

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
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
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, clear /var/lib/php/session, centos delete file, clear file centos, how to clear php session files linux, what is $cat in centos, centos ramcache sessions, php-session centos 6 6, linux delete php session files