会话文件无法清理

时间:2011-07-27 13:41:03

标签: php session

  

可能重复:
  cleanup php session files

即使在会话过期后,很多会话文件似乎也在我的会话文件夹(/home/mysite.com/sessions)中构建。我需要手动清除这些吗?

我打算写一个cron作业,但我不知道哪些会话文件是活动的,我不想只杀掉它们。

1 个答案:

答案 0 :(得分:7)

是的,您需要手动清理它们,因为您已经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 {} \;