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. 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.

  • 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
    Aug 19, 2015 at 17:18

3 Answers 3


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


If you set the 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.

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.

  • 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
    Nov 4, 2014 at 5:08

Here's one answer from 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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.