I see there are thousands of files in my "/tmp" directory (a CentOS machine) and almost all of them are PHP session files.
I'm worried about the possible impact this might have on my system.
Are those files ever deleted either by the OS, Apache or PHP? or I have to take care of it myself?
They should be deleted by the PHP garbage collector. The frequency is controlled by the
session.gc_maxlifetime
setting in php.ini. Possibly if this is not kicking in you have other problems.On default Debian and Ubuntu, the sessions are cleaned up by cron
/etc/cron.d/php5
where
/usr/lib/php5/maxlifetime
gives lifetime in minutes as set insession.gc_maxlifetime
.Also at reboot - as /tmp is always cleared out on reboot.
You could setup a cron script to clean them up automatically. It's generally a good idea to test for creation date older than what the life of cookies is set up to be on your system.
Limiting cookie life is done thusly (must be done before script outputs anything):
Then, in your cleanup script:
Then, in your crontab: