Over the years I have seen and worked with lots of sites that have had issues with session files not being cleared, this happens with a lot of sites but here I am going to details how to deal with Magento session files as this seems to be one of the most common ones that I get asked about, you may also be able to adapt parts of this to other web applications.
There are a number of ways that you can deal with Magento session files, one method is to save them in your database rather than saving them as files, another is to add a script to do this for you on a cron or just simply remember to manually deleted them.
Save In Database
To change the session storage to your database or to files edit your
app/etc/local.xml to one of the following
Save Sessions as files
Save Sessions in database
Using a PHP script to clean up Session Files
When using a script to clean up your session files this may not always work and is dependant on the quantity of files and other factors like php max execution time, if you try this and you are having issues then you may need to do a manual clean up first.
This php script should be setup to run on a cron every xx hours currently you will see it will delete files older than 24 hours but can be changes for longer or shorter periods.
<?php $dir = "var/session/"; //path to session files $interval = strtotime('-24 hours'); //files older than xx time -xx hours -xx minutes foreach (glob($dir."*") as $file) //delete if older if (filemtime($file) <= $interval ) unlink($file); ?>
Deleting files Manually via SSH (Linux Only)
locate the session folder and then issue a find command with the delete option to remove the seesion files, note that this may take time to complete depending on the amount of session files that have accumulated.
find /var/www/vhosts/yourdomain.tld/httpdocs/var/session/ -name sess_* -delete