# RFC: Add session_gc()

- Status: Implemented (PHP 7.1)
- Authors: Yasuo Ohgaki, yohgaki@ohgaki.net
- Version: 1.0
- Original: https://wiki.php.net/rfc/session-gc
- Page: https://externals.io/rfc/session-gc
- 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

## Votes

### Add session_gc() function (closed)

Yes: 12 · No: 0

Voters: bishop (Yes), cmb (Yes), colinodell (Yes), derick (Yes), diegopires (Yes), lstrojny (Yes), mariano (Yes), mike (Yes), stas (Yes), trowski (Yes), yohgaki (Yes), yunosh (Yes)

## Discussions on the mailing list

- [\[RFC\]\[Discussion\] Add session_gc()](https://externals.io/message/92121.md) — started on 2016-04-07, 25 messages
- [\[RFC\]\[VOTE\] Add session_gc() function](https://externals.io/message/94990.md) — started on 2016-08-10, 7 messages

---

## Introduction

Current session GC depends on probability. Thus, low traffic sites would not delete expired session data and could be usable as valid session. Traffic varies day and night time for high traffic sites. Chances are high that expired session may not be deleted as it should.

The best way to purge old session data is executing GC periodically.

Although timestamp based session management is declined twice, it is mandatory for session management. Please refer to Strict Session RFC for details.

- [https://wiki.php.net/rfc/precise\_session\_management](https://externals.io/rfc/precise_session_management)

## Proposal

- Add session\_gc() API.
- Document calling session\_gc() periodically is the best practice.

```
int session_gc(void)
```

It simply executes GC save handler defined.

## Backward Incompatible Changes

None

## Proposed PHP Version(s)

PHP 7.2

## Vote

This project requires a 2/3 majority. Vote starts: 2016/08/10 - Vote ends: 2016/08/17 23:59:59 UTC

**Vote: Add session\_gc() function** — Yes: 12 · No: 0 (closed)

## Patches and Tests

- <https://github.com/php/php-src/pull/1852>

## Implementation

After the project is implemented, this section should contain

1. the version(s) it was merged to 
    1. PHP 7.1 and master branch (Merged to PHP 7.1 also by RM permission)
2. a link to the git commit(s) 
    1. <http://git.php.net/?p=php-src.git;a=commitdiff;h=1cf179e4150308d8217d9517408ca5e22b5d607f>
3. a link to the PHP manual entry for the feature 
    1. [http://svn.php.net/viewvc?view=revision&amp;revision=339955](http://svn.php.net/viewvc?view=revision&revision=339955)

## References

- <https://bugs.php.net/bug.php?id=11100>
