Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-03T17:03:27.583Z
Answers.LastActivityDate: 2014-11-03T17:03:27.583Z
Answers.LastEditDate: 2017-05-23T12:38:53.957Z
Answers.UserDisplayName: user814584
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-25T01:50:11.463Z
Answers.LastActivityDate: 2016-02-25T01:50:11.463Z
Answers.UserDisplayName: jackmcpickle
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-04T05:08:27.207Z
Answers.Text: 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!
Answers.UserDisplayName: user814584
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-03T20:41:18.627Z
Answers.LastActivityDate: 2014-11-04T05:09:04.953Z
Answers.LastEditDate: 2014-11-04T05:09:04.953Z
Answers.UserDisplayName: Brad Bell
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-19T17:18:29.040Z
Comments.Text: 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.
Comments.UserDisplayName: Neal Magee
Tags: <php>
Title: Session Cleanup in Craft
ThreadText: # 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](https://stackoverflow.com/questions/654310/cleanup-php-session-files).
  
  ```
  # Every 30 minutes, not on the hour<br>
  # Grabs maxlifetime directly from \`php -i\`<br>
  # doesn't care if /var/lib/php5 exists, errs go to /dev/null<br>
  
  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
  
  
  ---
  
  