# [RFC][VOTE] Add session_gc() function

- Thread: https://externals.io/message/94990
- Original archive: https://news-web.php.net/php.internals/94990
- Started by Yasuo Ohgaki on 2016-08-10T09:30:41+00:00
- Messages: 7
- RFC: Add session_gc() (Implemented (PHP 7.1)) — https://externals.io/rfc/session-gc.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #94990 — Yasuo Ohgaki — 2016-08-10T09:30:41+00:00

URL: https://externals.io/message/94990#94990

Hi all,

This RFC is to add `session_gc()` function.

 `session_gc()` function is required API for periodic session GC that is
best practice for production web sites.

https://wiki.php.net/rfc/session-gc
It requires 2/3 majority to pass.
Vote starts: 2016/08/10  - Vote ends: 2016/08/17 23:59:59 UTC

Thank you for voting!

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #94992 — Marco Pivetta — 2016-08-10T09:32:34+00:00

URL: https://externals.io/message/94990#94992 · In reply to: #94990

Hey Yasuo,

Something is weird with the voting form, can you check it?

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/



> Hi all,
>
> This RFC is to add `session_gc()` function.
>
> `session_gc()` function is required API for periodic session GC that is
> best practice for production web sites.
>
> https://wiki.php.net/rfc/session-gc
> It requires 2/3 majority to pass.
> Vote starts: 2016/08/10  - Vote ends: 2016/08/17 23:59:59 UTC
>
> Thank you for voting!
>
> --
> Yasuo Ohgaki
> yohgaki@ohgaki.net

---

## #94999 — Yasuo Ohgaki — 2016-08-10T10:59:02+00:00

URL: https://externals.io/message/94990#94999 · In reply to: #94992

Hi Marco,


>
> Something is weird with the voting form, can you check it?

Thank you for letting me know!
I rewrited vote section immediately after I posted RFC vote notice
mail because it wasn't working for some reason. Something may be
caching the old page. Could you try to force reloading see if it
works?

Thank you!

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #95103 — Bishop Bettini — 2016-08-12T19:49:37+00:00

URL: https://externals.io/message/94990#95103 · In reply to: #94990

> Hi all,
>
> This RFC is to add `session_gc()` function.
>
> `session_gc()` function is required API for periodic session GC that is
> best practice for production web sites.
>
> https://wiki.php.net/rfc/session-gc
> It requires 2/3 majority to pass.
> Vote starts: 2016/08/10  - Vote ends: 2016/08/17 23:59:59 UTC
>

+1.

Should we document a polyfill, since the session GC firing logic can be
non-intuitive? Here's an attempt, anyhow:

function `session_gc()` {
    $initial = [
        `session_status()`,
        ini_get('session.gc_probability'),
        ini_get('session.gc_divisor'),
    ];
    if (PHP_SESSION_DISABLED === $initial[0]) {
        return false;
    }
    if (PHP_SESSION_ACTIVE === $initial[0]) {
        `session_write_close()`;
    }
    ini_set('session.gc_probability', 1);
    ini_set('session.gc_divisor',     1);
    `session_start()`;
    ini_set('session.gc_probability', $initial[1]);
    ini_set('session.gc_divisor',     $initial[2]);
    if (PHP_SESSION_NONE === $initial[0]) {
        `session_write_close()`;
    }
    return true;
}

---

## #95149 — Yasuo Ohgaki — 2016-08-14T21:39:03+00:00

URL: https://externals.io/message/94990#95149 · In reply to: #95103

Hi Bishop!


> 
> > […]
>
>
> +1.
>
> Should we document a polyfill, since the session GC firing logic can be
> non-intuitive? Here's an attempt, anyhow:
>
> function `session_gc()` {
>     $initial = [
>         `session_status()`,
>         ini_get('session.gc_probability'),
>         ini_get('session.gc_divisor'),
>     ];
>     if (PHP_SESSION_DISABLED === $initial[0]) {
>         return false;
>     }
>     if (PHP_SESSION_ACTIVE === $initial[0]) {
>         `session_write_close()`;
>     }
>     ini_set('session.gc_probability', 1);
>     ini_set('session.gc_divisor',     1);
>     `session_start()`;
>     ini_set('session.gc_probability', $initial[1]);
>     ini_set('session.gc_divisor',     $initial[2]);
>     if (PHP_SESSION_NONE === $initial[0]) {
>         `session_write_close()`;
>     }
>     return true;
> }

Thank you for the comment!
I'll add your example code in the manual.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #95273 — Pascal MARTIN — 2016-08-17T20:35:08+00:00

URL: https://externals.io/message/94990#95273 · In reply to: #94990

Le 10/08/2016 à 11:30, Yasuo Ohgaki a écrit :
> Hi all,
>
> This RFC is to add `session_gc()` function.

Hi,

We at AFUP would be +1 on this RFC to add a `session_gc()` function.

Basically: there are some situations were it could be useful and it's a 
quite self-contained change.

Thanks for you work on this!

-- 
Pascal MARTIN, AFUP - French UG
http://php-internals.afup.org/

---

## #95395 — Yasuo Ohgaki — 2016-08-22T22:35:05+00:00

URL: https://externals.io/message/94990#95395 · In reply to: #94990

Hi all,


>
> This RFC is to add `session_gc()` function.
>
> `session_gc()` function is required API for periodic session GC that is
> best practice for production web sites.
>
> https://wiki.php.net/rfc/session-gc
> It requires 2/3 majority to pass.
> Vote starts: 2016/08/10  - Vote ends: 2016/08/17 23:59:59 UTC
>
> Thank you for voting!

Sorry for the delay.
This RFC has passed by 12 vs 0.

Thank you for voting!
I'll merge and write manual soon.

Regards.

--
Yasuo Ohgaki
yohgaki@ohgaki.net
