不用
php.ini里面有相关的清除session的配置选项,把几率调高就可以了; Define the probability that the 'garbage collection' process is started
; on every session initialization.
; The probability is calculated by using gc_probability/gc_divisor,
; e.g. 1/100 means there is a 1% chance that the GC process starts
; on each request.session.gc_probability = 1
session.gc_divisor     = 1000; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
session.gc_maxlifetime = 1440
默认是1000,就是说有1000次访问请求会激活一次超过session生存期的临时文件。
如果你的网站访问量很大可以提高此几率,如果你的网站访问量小可以调低,根据你的实践来定