<p>Here's one answer from <a href="https://stackoverflow.com/questions/654310/cleanup-php-session-files">cleanup php session files</a>.</p>

<pre><code># Every 30 minutes, not on the hour&lt;br&gt;
# Grabs maxlifetime directly from \`php -i\`&lt;br&gt;
# doesn't care if /var/lib/php5 exists, errs go to /dev/null&lt;br&gt;

09,39 * * * *   find /var/www/craft/storage/runtime/sessions -type f -cmin +60 -exec rm -f {} +  &gt;/dev/null 2&gt;&amp;1
</code></pre>

CC BY-SA 3.0
2014-11-03T17:03:27.583Z
2014-11-03T17:03:27.583Z
2017-05-23T12:38:53.957Z
user814584
<p>We use redis to store cache and now sessions. </p>

<p>Just got this working with </p>

<p><code>'cacheMethod' =&gt; 'redis',
'overridePhpSessionLocation' =&gt; 'tcp://redis.dev:6379'</code> in my general.php</p>

<p>and <code>ini_set('session.save_handler', 'redis');</code> in my index.php</p>

CC BY-SA 3.0
2016-02-25T01:50:11.463Z
2016-02-25T01:50:11.463Z
jackmcpickle
<p>Apparently PHP's garbage collection does <em>not</em> work when you've set a custom PHP session save path.</p>

<p>Lame.</p>

<p>If you set the <a href="http://buildwithcraft.com/docs/config-settings#overridePhpSessionLocation">overridePhpSessionLocation</a> config setting to false, Craft will go with whatever path Apache/PHP is configured to save sessions to. If you're not on shared hosting, then it's a perfectly safe change, too.</p>

<p>Setting that to false on a site that is on shared hosting has its <a href="http://websec.io/2012/08/24/Shared-Hosting-PHP-Session-Security.html">own security implications</a>.</p>

<blockquote>
  <p>curious if there is work being done on Craft to fix this issue by default.</p>
</blockquote>

<p>We're discussing what we can do in Craft itself to help with this.</p>

CC BY-SA 3.0
2014-11-04T05:08:27.207Z
I use VPS's exclusively so I think I will just set overridePhpSessionLocation to false. I wasn't sure if that would cause other issues or not, but it sounds like in our situation it will not. Thanks!
user814584
CC BY-SA 3.0
2014-11-03T20:41:18.627Z
2014-11-04T05:09:04.953Z
2014-11-04T05:09:04.953Z
Brad Bell
<p>Just had an e-commerce site go down due to Craft's custom way of handling Sessions. The session directory never gets cleaned up, causing the sessions folder to be littered with tens to hundreds of thousands of orphaned files, causing my server to run out of inodes. PHP has a built in utility to deal with this, but that doesn't work since Craft sets a <a href="http://ar.php.net/manual/en/session.configuration.php#ini.session.save-path">custom session directory</a>. Looking for a good cron job or other utility that will automatically clean this folder up automatically.</p>

<p>Also, curious if there is work being done on Craft to fix this issue by default. I wonder if the reason it hasn't become as big of an issue as it seems it is (only found a handful of people mentioning it on the Google Plus page), is because Craft hasn't been out long enough for some sites to experience this yet, but they may soon. It took about 4 months for the session directory to get too full on a pretty small hard drive, so I wonder if a number of other sites with bigger hard drives currently have this issue behind the scenes, and haven't experienced any problems yet, but will soon.  </p>

CC BY-SA 3.0
2015-08-19T17:18:29.040Z
I just had this issue occur on a cluster of EC2 instances running Craft. I hadn't thought of inodes being depleted until I could see more detailed error messages that there was no space left on the device (but there was!).

I wrote something like the crontab script below, so it's good to see that method verified here. A brute force trimming job may not be elegant, but necessary in this case.
Neal Magee
<php>
Session Cleanup in Craft
# Session Cleanup in Craft

(Asked by: username_0 on 2014-11-03)

Just had an e-commerce site go down due to Craft's custom way of handling Sessions. The session directory never gets cleaned up, causing the sessions folder to be littered with tens to hundreds of thousands of orphaned files, causing my server to run out of inodes. PHP has a built in utility to deal with this, but that doesn't work since Craft sets a [custom session directory](http://ar.php.net/manual/en/session.configuration.php#ini.session.save-path). Looking for a good cron job or other utility that will automatically clean this folder up automatically.

Also, curious if there is work being done on Craft to fix this issue by default. I wonder if the reason it hasn't become as big of an issue as it seems it is (only found a handful of people mentioning it on the Google Plus page), is because Craft hasn't been out long enough for some sites to experience this yet, but they may soon. It took about 4 months for the session directory to get too full on a pretty small hard drive, so I wonder if a number of other sites with bigger hard drives currently have this issue behind the scenes, and haven't experienced any problems yet, but will soon.

**Tags:** php

> **Comments:**
> **username_1**: I just had this issue occur on a cluster of EC2 instances running Craft. I hadn't thought of inodes being depleted until I could see more detailed error messages that there was no space left on the device (but there was!).  I wrote something like the crontab script below, so it's good to see that method verified here. A brute force trimming job may not be elegant, but necessary in this case.  

---

## 3 answers

### Answer by username_3 on 2014-11-03. Score: 6 | Accepted answer

Apparently PHP's garbage collection does *not* work when you've set a custom PHP session save path.

Lame.

If you set the [overridePhpSessionLocation](http://buildwithcraft.com/docs/config-settings#overridePhpSessionLocation) config setting to false, Craft will go with whatever path Apache/PHP is configured to save sessions to. If you're not on shared hosting, then it's a perfectly safe change, too.

Setting that to false on a site that is on shared hosting has its [own security implications](http://websec.io/2012/08/24/Shared-Hosting-PHP-Session-Security.html).

> curious if there is work being done on Craft to fix this issue by default.

We're discussing what we can do in Craft itself to help with this.

> **Comments:**
> **username_0**: I use VPS's exclusively so I think I will just set overridePhpSessionLocation to false. I wasn't sure if that would cause other issues or not, but it sounds like in our situation it will not. Thanks!  

---

### Answer by username_0 on 2014-11-03. Score: 4

Here's one answer from cleanup php session files.
# Every 30 minutes, not on the hour
# Grabs maxlifetime directly from \`php -i\`
# doesn't care if /var/lib/php5 exists, errs go to /dev/null

09,39 * * * *   find /var/www/craft/storage/runtime/sessions -type f -cmin +60 -exec rm -f {} +  >/dev/null 2>&1


---

### Answer by username_2 on 2016-02-25. Score: 3

We use redis to store cache and now sessions.

Just got this working with

`'cacheMethod' => 'redis',
'overridePhpSessionLocation' => 'tcp://redis.dev:6379'` in my general.php

and `ini_set('session.save_handler', 'redis');` in my index.php


---

