Script to delete PHP session files to keep inode usage to minimum


 

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
-------------------------------------

 


Detailed How To

In linux containers, inode is a precious resource which limits number of file/folders that could be stored in server.

We noticed that sessions files could often result in high inode usage since old sessions files are not deleted from server.

This KB article will help to easily clean up old & unused session files.

 
Steps to configure the script to automatically delete  old & unused session files.


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. Test the script

The script can be executed as given below to find out session files it is going to delete

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

Example:
--------------------------------------------------
bash-4.1# /root/bhscripts/clean-php-session-files.sh

PHPSESSIONPATH=/var/lib/php/session
PHPSESSIONLIFETIME=1440
PHPSESSIONLIFETIMEMINUTE=24

If you wish to delete session files in /var/lib/php/session, please run the script as given below.

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

3. Deleting session files using the script

The script can be executed as given below to find out session files it is going to delete

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

Example:
--------------------------------------------------
bash-4.1# /root/bhscripts/clean-php-session-files.sh delete
bash-4.1#
--------------------------------------------------

4. Configuring a cron job to hourly delete old session files.

Add following cron job as root.

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

Last update:
2014-10-27 03:25
Author:
Sherin George
Revision:
1.3
Average rating: 1 (1 Vote)

You cannot comment on this entry

Chuck Norris has counted to infinity. Twice.

Records in this category

Tags

top