H
H
HaruAtari2014-04-26 19:16:07
PHP
HaruAtari, 2014-04-26 19:16:07

Apache: how to remove old sessions from a custom directory

Good evening.
There is a site whose session files are not in the default directory, but in a separate directory. This is specified via .htaccess
php_value session.save_path './../_sessions'
Files are saved to this directory. Only here's the trouble - the old sessions will not be deleted. The server config specifies a session lifetime of 10 minutes. But files from this directory are not deleted. Rights are enough.
I thought, maybe if it's a custom directory, then you need to delete it yourself? But something tells me it's wrong.
Tell me what could be the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vlad Zhivotnev, 2014-04-26
@HaruAtari

You won't believe it, but in a regular directory, session files are also deleted "by hand" +)

root@master:~# cat /etc/cron.d/php5 
# /etc/cron.d/php5: crontab fragment for php5
#  This purges session files older than X, where X is defined in seconds
#  as the largest value of session.gc_maxlifetime from all your php.ini
#  files, or 24 minutes if not defined.  See /usr/lib/php5/maxlifetime

# Look for and purge old sessions every 30 minutes
09,39 *     * * *     root   [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -type f -cmin +$(/usr/lib/php5/maxlifetime) -delete

I prefer something like this:
[email protected]:~# cat /usr/bin/clear_sess.sh 
#!/bin/bash
/usr/bin/find /var/lib/php52 -mmin  +XXX -delete -print
# где XXX - количество минут (правда, у меня в днях mtime).

And then I run it in the cron via flock:
flock -n /tmp/clear-sess.lock -c /usr/bin/clear-sess.sh

D
Dunadan, 2014-05-03
@Dunadan

If possible, it is better to transfer the storage of sessions to memcash.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question