PHP5.3的Session有效期默认是多少?有人说24分钟,有人说180分钟,我试了一下,好久好久都没过期,这是怎么一种情况呢?

解决方案 »

  1.   

    24分钟,至于说180分钟的,可能某个5.x的版本默认是吧
     不知道你是怎么试的session.gc_maxlifetime = 1440; 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):
    ;          find /path/to/sessions -cmin +24 | xargs rm
      

  2.   

    1451 ; Defines the probability that the 'garbage collection' process is started
    1452 ; on every session initialization. The probability is calculated by using
    1453 ; gc_probability/gc_divisor. Where session.gc_probability is the numerator
    1454 ; and gc_divisor is the denominator in the equation. Setting this value to 1
    1455 ; when the session.gc_divisor value is 100 will give you approximately a 1% chance
    1456 ; the gc will run on any give request.
    1457 ; Default Value: 1
    1458 ; Development Value: 1
    1459 ; Production Value: 1
    1460 ; http://php.net/session.gc-probability
    1461 session.gc_probability = 1
    1462 
    1463 ; Defines the probability that the 'garbage collection' process is started on every
    1464 ; session initialization. The probability is calculated by using the following equation:
    1465 ; gc_probability/gc_divisor. Where session.gc_probability is the numerator and
    1466 ; session.gc_divisor is the denominator in the equation. Setting this value to 1
    1467 ; when the session.gc_divisor value is 100 will give you approximately a 1% chance
    1468 ; the gc will run on any give request. Increasing this value to 1000 will give you
    1469 ; a 0.1% chance the gc will run on any give request. For high volume production servers,
    1470 ; this is a more efficient approach.
    1471 ; Default Value: 100
    1472 ; Development Value: 1000
    1473 ; Production Value: 1000
    1474 ; http://php.net/session.gc-divisor
    1475 session.gc_divisor = 1000
    1476 
    1477 ; After this number of seconds, stored data will be seen as 'garbage' and
    1478 ; cleaned up by the garbage collection process.
    1479 ; http://php.net/session.gc-maxlifetime
    1480 session.gc_maxlifetime = 1440共同作用。
      

  3.   

    php.ini 中有
    session.gc_probability = 1
    session.gc_divisor = 1000
    session.gc_maxlifetime = 1440表示特定 sessionid 临时文件将在 24 分钟后有千分之一的可能被删除,运气不好的话可能要在 24000 分钟后才被删除
    sessionid 临时文件被删除了,才表示该 sessionid 真正的失效了
      

  4.   


    ++想要百分百触发,就让pro和div都是1,另外可以让session很长很长,设置maxlifetime即可。 只有服务端session文件长没用,要保持客户端cookie的生命期长度一致。