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

Apache - Address already in use: make_sock: could not bind to address

Apache - Address already in use: make_sock: could not bind to address This error message can be...

Slow ssh authentication

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

Improve ProFTPD performance

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

FTP uploads have wrong permissions

When files are created in a folder via FTP, the permisions are not set to those of the folder....

Run .cgi outside cgi-bin directory

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