Welcome Guest, Not a member yet? Register   Sign In
Website crashing, only fixed by clearing session files
#1

I've had 2 times in recent days where my site has crashed (500 error from CodeIgniter, Apache is working otherwise) but there's nothing logged in the PHP or CI logs. The only solution I can find is to clear out the /writable/session directory.
Has anybody else seen this? Kinda seems like a hard drive issue, but I've verified that I have plenty of space on my server volume. Session directory is showing 3,184,750 files using a combined 5.9GB of space on the drive.
  • CI 4.3.2
  • 2GB DigitalOcean Droplet with attached 150 GB volume (about 20GB used)

Thanks
James
Designer, developer and Diet Dr. Pepper addict. Messing up PHP since <?= $when['year';] ?>
Reply
#2

3,184,750 files seems too many.

1. Is it possible on your server? Ask the technical support in DigitalOcean.
2. Do you really need so many session files?
Reply
#3

I definitely don't need all those old session files, but they have been piling up for months.

I was able to clear out a bunch of old ones by running this command:
find /mnt/volume/www/MYSITE/writable/session -type f ! -newermt "1 month ago" -delete

That left about 519k session files (from the last month) in place for now.

Does CodeIgniter manage this storage somehow? Does Spark do this?

I read something about a garbage collector in the docs. Could this be what is supposed to keep my session directory clean?
Designer, developer and Diet Dr. Pepper addict. Messing up PHP since <?= $when['year';] ?>
Reply
#4

> Does CodeIgniter manage this storage somehow? Does Spark do this?

No.

PHP does probability based session GC by default. But it is not recommended.
See https://www.php.net/manual/en/function.session-gc.php

I recommend you run the find command by cron.
Reply
#5

That sounds like a good path forward. Thanks for your help!
Designer, developer and Diet Dr. Pepper addict. Messing up PHP since <?= $when['year';] ?>
Reply
#6

I had this problem.
Some shared hosting disables automatic garbage collection.
On my server, session.gc_probability is set to 0.
There is a server CRON job in place to remove garbage. However, this will never find the files CodeIgniter has created.

You have to set ini values for
session.gc_probability and session.gc_divisor

In my /common.php I placed the following

Code:
// enable garbage collection
ini_set('session.gc_divisor', 10);
ini_set('session.gc_probability', 1);
Reply




Theme © iAndrew 2016 - Forum software by © MyBB