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

Using rsync to copy files

Here is a good guide on how to sync folders using...

Clear postfix mail queue

Show QueuePostqueue -pDelete mail to/from mailboxpostqueue -p | tail -n +2 | awk 'BEGIN { RS = ""...

Run .cgi outside cgi-bin directory

By default runs CGI scripts in /cgi-bin/ folder only. To allow CGI scripts be processed from...

How to change mail server ip address for qmail

1) first check the domain names which are configured on the server by viewing following file...

Improve ProFTPD performance

A quick fix to fix connectivity or slow connection issues when using ProFTPD is to edit some of...