For Magento CMS and the like (that aren't cleaning old sessions up), I just use cron jobs based on php.ini settings.
PHP5/Ubuntu 14.04/Debian
The system cron.d setup for php5 does not clean Magento ./var/session (or anything besides default session folder (/var/lib/php5 for Ubuntu and /var/lib/php5/sessions or /tmp/ for most others Linux dists).
But you can still use "sessionclean" and "maxlifetime" as per the default php5/Debian system cron:
Example you can try from Command line:
# sudo /usr/lib/php5/sessionclean /var/www/{yoursite}/var/session $(/usr/lib/php5/maxlifetime)
So just incorporate that into a system/root crontab or a crontab of user who has read/write permission for the session files:
$ sudo crontab -e
Add this is you want it to look similar to system php cron:
20,40 * * * * [ -x /usr/lib/php5/maxlifetime ] && [ -x /usr/lib/php5/sessionclean ] && [ -d /var/www/*/var/session ] && /usr/lib/php5/sessionclean /var/www/{yoursite}/var/session $(/usr/lib/php5/maxlifetime)
or - since we know those files/dirs exist:
20,40 * * * * /usr/lib/php5/sessionclean /var/www/*/var/session $(/usr/lib/php5/maxlifetime)
Now I have a manageable amount of sessions and it is kept clean via default garbage collection/lifetime via php.ini (cli) settings.
(You may leave the wildcard above or replace with sitename.)
EDIT (PHP7 / Ubuntu 16.xx / Debian):
The 'sessionclean' script has changed and maxlifetime script has been removed. For the system/php cron job it is now one script. You cannot really use this anymore as the file calls are now static to script.
The older php5 sessionclean script can still work for you if the system isn't cleaning up. What you can do is grab the older Debian php5 Package and extract sessionclean
from it. Or you can simply copy this to your scripts area (giving proper /var/www/(site) permissions/ownership) :
#!/bin/sh
# first find all used files and touch them (hope it's not massive amount of files)
[ -x /usr/bin/lsof ] && /usr/bin/lsof -w -l +d "${1}" | awk -- '{ if (NR > 1) { print $9; } }' | xargs -i touch -c {}
# find all files older then maxlifetime
find "${1}" -depth -mindepth 1 -maxdepth 1 -ignore_readdir_race -type f -cmin "+${2}" -delete
I also recommend renaming it, so it's not confused with the new php 'sessionclean' cronjob. You can then plug your own "maxlifetime" number in like so:
20,40 * * * * /home/-username-/scripts/MySessionClean /var/www/*/var/session 61
(61 being the example age (in minutes) and 'MySessionClean' being the renamed php5 script downloaded or copied from above).
In this manner we avoid php.ini/env calls entirely.
(EDIT 13DEC2016: Updated DEBIAN ARCHIVE REPO LINK)