NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP Sessions, Expiration, and all that

Cliff Hirsch cliff at pinestream.com
Fri May 4 10:08:47 EDT 2007


On 5/4/07 9:23 AM, "Chris Shiflett" <shiflett at php.net> wrote:

> Hi Paul,
> 
>> Our client wants sessions to time out after six hours of
>> inactivity, and I'm wondering if there's an easy way to do
>> that by configuring PHP.
> 
> Yes, but keep in mind that session.gc_maxlifetime indicates a maximum,
> not a minimum. PHP isn't going to check on every request to see whether
> it should clean up stale sessions; there's some probability involved.
> However, you can change that, too. :-)
> 
>> $now=time();
>> if(isset($_SESSION["timestamp"])) {
>>    ... dump session if now-timestamp > limit ...
>> }
>> $_SESSION["timestamp"]=$now;
> 
> Seems like a fine way to do it to me.
> 
> Chris

Why not kill the GC function and add a cron job instead? More predictable,
less overhead.

Cliff





More information about the talk mailing list