Purge tmp directory per user

user160403 asked:

I’ve created on my fresh server a directory structure like this:

/home/$username/$domain/ (for example: /home/domaincom/domain.com/)
– public_html
– logs
– conf
– tmp

Everything works well, but unfortunatelly, apache (or PHP) is not purging tmp directory automaticly. :/

Is there a simple way to purge those directories? For example a solution like logrotate, where I set directory to rotate like this: / home / * / * / logs

Problem appeared because on user temp directory has 1562074 files. :/ I’m not sure who (apache, php, external script) should clean this directory and how often.

Apache or php is not obligated to clean unused temp files (mostly sess_…)?

Thanks for any answers. 🙂

My answer:

You changed the default PHP session save path.

On a Debian system, the PHP directive session.gc_probability is set to 0, preventing old sessions from being cleaned up, and a cron job is set up that clears out the old PHP sessions – but only from the default save path!

So you can fix this in one of two ways:

  1. Change the PHP session save path back to its default.
  2. Set session.gc_probability = 1 in php.ini.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.