Monday, December 8, 2014

Deleting expired PHP session files on Ubuntu 14.04

Everything started with MySQL not being able to start.



After some web searching I found out that the server ran out of inodes.



df -i



Filesystem     Inodes  IUsed  IFree IUse% Mounted on
/dev/simfs 500000 500000 0 100% /
none 131072 56 131016 1% /dev
none 131072 1 131071 1% /sys/fs/cgroup

none 131072 63 131009 1% /run
none 131072 4 131068 1% /run/lock
none 131072 1 131071 1% /run/shm
none 131072 1 131071 1% /run/user


Further googling led me to the assumption that the PHP session files never get deleted... which seem to be true because running ls php5 | wc -l gives me 424669!



I read that the PHP.ini session.gc_probability is set to 0 by default and that ubuntu handles the cleanup through the cronjob /etc/cron.d/php5.




/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 ] && [ -x /usr/lib/php5/sessionclean ] && [ -d /var/lib/php5 ] && /usr/lib/php5/sessionclean /var/lib/php5 $(/usr/lib/php5/maxlifetime)



This looks right, so why isn't this script working? Is there a way for me to confirm that this is actually run every 30 minutes?

No comments:

Post a Comment