PHP Session 的 garbage collection 不會運作的原因

分類: 技術分享 作者: admin

16 10 月 2008
PHP 的 Session 預設是 1440 秒 (24分鐘) 清空一次,但是如果更改了session.save_path 設定,Session garbage collection 就不會再動作了。
這時候就要用 crontab 手動清理:
cd /path/to/sessions; find -cmin +24 | xargs rm
註:+24 代表檔案更新日期為 24 分鐘前
; 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