delete php sessions to free inodes.

Quick How To for the Impatient


 1. Run following script to download clean-php-session-files.sh script

-------------------------------------------------------------------
mkdir /root/bhscripts
cd  /root/bhscripts
wget http://files.bytehouse.co.uk/clean-php-session-files.sh
chmod 755 /root/bhscripts/clean-php-session-files.sh
-------------------------------------------------------------------

2. Configure a cron job to hourly delete old session files.

-------------------------------------
0 * * * * /root/bhscripts/clean-php-session-files.sh delete >/dev/null 2>&1
-------------------------------------

Full details here... https://kb.bytehouse.co.uk/content/12/42/en/script-to-delete-php-session-files-to-keep-inode-usage-to-minimum.html
Big thanks to Bytehouse KB

Scipt content:-

#!/bin/bash                                                                                         

deletepermission=$1

export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

PHPSESSIONPATH=$(php -i 2>/dev/null | grep -w session.save_path | awk '{print $3}' | head -1);
PHPSESSIONLIFETIME=$(php -i 2>/dev/null | grep -w session.gc_maxlifetime | awk '{print $3}' | head -1);
PHPSESSIONLIFETIMEMINUTE=$( expr $PHPSESSIONLIFETIME / 60 );

if [[ $deletepermission = "delete" ]]
then

find $PHPSESSIONPATH -type f -cmin +$PHPSESSIONLIFETIMEMINUTE -name "sess_*" -exec rm -f {} \;

else

echo "
PHPSESSIONPATH=$PHPSESSIONPATH
PHPSESSIONLIFETIME=$PHPSESSIONLIFETIME
PHPSESSIONLIFETIMEMINUTE=$PHPSESSIONLIFETIMEMINUTE

If you wish to delete session files in $PHPSESSIONPATH, please run the script as given below.

-------------------------------------------------------
/root/bhscripts/clean-php-session-files.sh delete
-------------------------------------------------------

";

fi


Was this answer helpful?

 Print this Article

Also Read

Remove malicious web code

http://iscanner.isecur1ty.org/

What can I use instead of TreeSize

There is a Windows program called Tree Size which shows disk usage. You can tell how much each...

Install SNMP (Centos)

Centos6yum -y install snmp Centos7yum install net-snmp net-snmp-utils rename the file:...

Slow ssh authentication

Problem: ssh login takes up to 30 seconds. Solution: It is likely to be a Reverse DNS issue....

Backup mysql database

mysqldump -u root -p databasename > databasename.sql If you are using plesk, replace root...