【发布时间】:2011-10-14 06:58:39
【问题描述】:
很多会话文件似乎在我的会话文件夹 (/home/mysite.com/sessions) 中建立,即使会话过期也是如此。我需要手动清除这些吗?
我打算编写一个 cron 作业,但我不知道哪些会话文件处于活动状态,我不想将它们全部杀死。
【问题讨论】:
很多会话文件似乎在我的会话文件夹 (/home/mysite.com/sessions) 中建立,即使会话过期也是如此。我需要手动清除这些吗?
我打算编写一个 cron 作业,但我不知道哪些会话文件处于活动状态,我不想将它们全部杀死。
【问题讨论】:
是的,您需要手动清理它们,因为您有 setup your own session save path。您可以检查文件的年龄并删除它是否超过 x 天/分钟:
cd /path/to/sessions; find -cmin +24 | xargs rm
取自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
请参阅这个相关/重复的问题:cleanup php session files
“单个”命令:
find /path/to/session -name sess_* -cmin +24 -exec rm {} \;
【讨论】: