Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session Files Not Getting Cleaned Up [duplicate]

Tags:

php

session

Possible Duplicate:
cleanup php session files

A lot of session files seem to be building up in my sessions folder (/home/mysite.com/sessions), even after the session expires. Do I need to manually clear these out?

I was going to write a cron job, but I can't tell which session files are active, and I don't want to just kill them all.

like image 852
Rich Darvins Avatar asked Jan 19 '23 03:01

Rich Darvins


1 Answers

Yes, you need to manually clean them up because you've setup your own session save path. You can check the age of a file and delete if it's older than x days/minutes whatever:

cd /path/to/sessions; find -cmin +24 | xargs rm

Taken from the note part of php.ini:

; NOTE: If you are using the subdirectory option for storing session files
;       (see session.save_path above), then garbage collection does *not*
;       happen automatically.  You will need to do your own garbage
;       collection through a shell script, cron entry, or some other method.
;       For example, the following script would is the equivalent of
;       setting session.gc_maxlifetime to 1440 (1440 seconds = 24 minutes):
;          cd /path/to/sessions; find -cmin +24 | xargs rm

See as well this related/duplicate question: cleanup php session files


"Single" command:

find /path/to/session -name sess_* -cmin +24 -exec rm {} \;
like image 186
hakre Avatar answered Jan 31 '23 10:01

hakre