librelist archives

« back to archive

How to remove old sessions ?

How to remove old sessions ?

From:
William Martin
Date:
2012-05-09 @ 12:51
Hi,

With the current session / auth system, we quickly have lot of old
session without cookie to point on it.
How do you handle the cleanup of the session storage ?

William

Re: [photon.users] How to remove old sessions ?

From:
Loic d'Anterroches
Date:
2012-05-14 @ 11:51
Hello,

> With the current session / auth system, we quickly have lot of old
> session without cookie to point on it.
> How do you handle the cleanup of the session storage ?

This is my commit() code of my session storage. You see the "t" time,
which allows me to basically select all the sessions with last
modification time greater than a month and remove them.

loïc


    /**
     * Given the response object, save the data.
     *
     * The commit call must ensure that $this->key is set afterwards.
     *
     * @required public function commit($response=null)
     */
    public function commit($response)
    {
        if (null === $this->key) {
            $this->key = $this->getNewKey(json_encode($response->headers));
        }
        $data = array('_id' => $this->key,
                      'd' => $this->data,
                      't' => time());

        DB::get()->sessions->update(array('_id' => $this->key), $data,
                                    array('upsert' => true));

        return $this->key;
    }

Re: [photon.users] How to remove old sessions ?

From:
William Martin
Date:
2012-05-14 @ 12:01
Thanks loic,

What do you thinks about send a event when you call the garbage
collector in the server code [1] ?
It's will allow us to run GC at the application level (i.e. old sessions)

William

[1] 
http://projects.ceondo.com/p/photon/source/tree/master/src/photon/server.php#L196

On Mon, May 14, 2012 at 1:51 PM, Loic d'Anterroches <loic@ceondo.com> wrote:
> Hello,
>
>> With the current session / auth system, we quickly have lot of old
>> session without cookie to point on it.
>> How do you handle the cleanup of the session storage ?
>
> This is my commit() code of my session storage. You see the "t" time,
> which allows me to basically select all the sessions with last
> modification time greater than a month and remove them.
>
> loïc
>
>
>    /**
>     * Given the response object, save the data.
>     *
>     * The commit call must ensure that $this->key is set afterwards.
>     *
>     * @required public function commit($response=null)
>     */
>    public function commit($response)
>    {
>        if (null === $this->key) {
>            $this->key = $this->getNewKey(json_encode($response->headers));
>        }
>        $data = array('_id' => $this->key,
>                      'd' => $this->data,
>                      't' => time());
>
>        DB::get()->sessions->update(array('_id' => $this->key), $data,
>                                    array('upsert' => true));
>
>        return $this->key;
>    }



-- 
---------------------------------------------------------
William MARTIN
wysman @NoSpAm@ gmail @DoT@ com

Re: [photon.users] How to remove old sessions ?

From:
Loic d'Anterroches
Date:
2012-05-14 @ 12:05

On 2012-05-14 14:01, William MARTIN wrote:
> Thanks loic,
> 
> What do you thinks about send a event when you call the garbage
> collector in the server code [1] ?
> It's will allow us to run GC at the application level (i.e. old sessions)

Ok. You can put an event. The only thing you need to be aware of is that
we will send it every 500 requests for *each* photon process. So, your
code should be smart to run your "cron like" job only if not run in the
last "X" time or so with the last time stored in a central place.

Also, when doing so, requests will wait, so you have an handler which is
not answering. This can be an issue if your "cron" like job takes more
than a few 100 ms.

Of course, you could also create a long running task (worker) just doing
cron like jobs in the future if this starts to be an issue.

loïc

> [1] 
http://projects.ceondo.com/p/photon/source/tree/master/src/photon/server.php#L196
> 
> On Mon, May 14, 2012 at 1:51 PM, Loic d'Anterroches <loic@ceondo.com> wrote:
>> Hello,
>>
>>> With the current session / auth system, we quickly have lot of old
>>> session without cookie to point on it.
>>> How do you handle the cleanup of the session storage ?
>>
>> This is my commit() code of my session storage. You see the "t" time,
>> which allows me to basically select all the sessions with last
>> modification time greater than a month and remove them.
>>
>> loïc
>>
>>
>>    /**
>>     * Given the response object, save the data.
>>     *
>>     * The commit call must ensure that $this->key is set afterwards.
>>     *
>>     * @required public function commit($response=null)
>>     */
>>    public function commit($response)
>>    {
>>        if (null === $this->key) {
>>            $this->key = $this->getNewKey(json_encode($response->headers));
>>        }
>>        $data = array('_id' => $this->key,
>>                      'd' => $this->data,
>>                      't' => time());
>>
>>        DB::get()->sessions->update(array('_id' => $this->key), $data,
>>                                    array('upsert' => true));
>>
>>        return $this->key;
>>    }
> 
> 
>