# No autoremove of session files ? (in app/tmp/sessions , Cakephp2)

**URL:** <https://discourse.cakephp.org/t/no-autoremove-of-session-files-in-app-tmp-sessions-cakephp2/10158>\
**Category:** Need Help\
**Created:** [February 11, 2022, 2:12pm UTC](https://discourse.cakephp.org/t/no-autoremove-of-session-files-in-app-tmp-sessions-cakephp2/10158 "2022-02-11T14:12:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Donny](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Donny](https://discourse.cakephp.org/u/Donny)\
**Post date:** [February 11, 2022, 2:12pm UTC](https://discourse.cakephp.org/t/no-autoremove-of-session-files-in-app-tmp-sessions-cakephp2/10158/1 "2022-02-11T14:12:28Z")

</div>

Hello,

I wonder if there’s a ready-way to auto remove expired session files?

`timeout` won’t delete the session file and will just make it expired, and the file won’t be deleted from app/tmp/sessions. In a long term it can take a lot of space in the server if you have traffic.

```auto
Configure::write('Session', array(
		'defaults' => 'cake',
		'timeout' => 1, //36000
	));

```

Otherwise I’ll probably do a script or a php function that checks regularly the session files to remove old ones based on their modification date.

Regards

---

<div class="post-metadata">

**Author:** ![ndm](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/ndm/32/2234_2.png) [@ndm](https://discourse.cakephp.org/u/ndm)\
**Post date:** [February 11, 2022, 7:28pm UTC](https://discourse.cakephp.org/t/no-autoremove-of-session-files-in-app-tmp-sessions-cakephp2/10158/2 "2022-02-11T19:28:09Z")

</div>

Session timeout and session garbage collection are two different operations, and the latter doesn’t happen immediately, but with a certain probability on session startup.

You have to [configure the relevant PHP INI settings](https://book.cakephp.org/2/en/development/sessions.html#setting-ini-directives) accordingly, check [`session.gc_probability`](https://www.php.net/manual/en/session.configuration.php#ini.session.gc-probability), [`session.gc_divisor`](https://www.php.net/manual/en/session.configuration.php#ini.session.gc-divisor), and [`session.gc_maxlifetime`](https://www.php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetime) (this one is being set automatically by CakePHP, derived from the `timeout` option).
