Help - Millions of sess_ files in tmp folder

Permalink
Hello,

My client's files/tmp folder keeps filling with millions of files that begin with sess_ presumably files that keep track of session data. They are not being cleaned out automatically, and they take forever to clean out manually unless we do so frequently. What can be done about this?

Best,

Joey

CommotionCreative
 
ConcreteOwl replied on at Permalink Reply
ConcreteOwl
Well,
Until a "Job" is included in the optimization section to deal with the clearing out of the tmp folder,
You can simply delete the tmp folder because it will be re-created automatically as a new folder to hold the latest session file,
Not ideal but for the moment a quicker solution than deleting the individual sess files.
grosbedo replied on at Permalink Reply
Thank's for the input, but indeed I suffer from the same problem. This should be added in the TODO list for the next release.
Phallanx replied on at Permalink Reply
Phallanx
abberdab replied on at Permalink Reply
abberdab
I'm struggling with this, too. Trying to back up a site before upgrading from 5.6.0.2 to 5.6.1 and the /tmp/ directory is killing me. Unable to zip from the command line on my web server and deleting the /tmp/ directory in prep for zipping has taken 1:42 minutes so far (it's still "rm"-ing). I think its massive bloatiness might be the reason why backup cron jobs on this server haven't been completing.

Ugh ugh ugh.

I sure hope this is fixed in 5.6.1. Really feeling like I'm getting dinged for my pre-upgrade due diligence here. This was supposed to be a simple, one-click upgrade. :(

(I checked my php configuration and all seemed to be in order.)
mhawke replied on at Permalink Reply
mhawke
Have you asked your host about it? Shouldn't their 'garbage clean-up' routines be expiring the sessions and deleting them.
abberdab replied on at Permalink Reply
abberdab
Thanks for the direction, mhawke. I'll ping them and find out. :)
Hypocrite replied on at Permalink Reply
Hypocrite
We have also this problem with 5.6.2.

If I understasnd, the php.ini setting only destroyes sessions in the default /tmp/ folder.

But concrete5 saves them in /files/tmp/ under the install folder.

The server does not clean this folder by default?
mhawke replied on at Permalink Reply
mhawke
Add these lines to your [root]/config/site.php

define('DIR_SESSIONS', sys_get_temp_dir());
define('DIR_TMP', sys_get_temp_dir());
Remo replied on at Permalink Reply
Remo
Not sure, but maybe this helps too?
http://www.concrete5.org/marketplace/addons/cache-vac/...
Hypocrite replied on at Permalink Reply
Hypocrite
mhawke replied on at Permalink Reply
mhawke
I don't believe that add-on touches the /files/tmp folder.

I dug through the code and found where c5 determines it's storage loactions.

'DIR_TMP' is determined on line #150 of [root]/concrete/core/helpers/file.php

'DIR_SESSIONS' is determeined on line #29 of [root]/concrete/startup/file_permission_config.php

As soon as I defined these variables in my site.php file as noted above, the problem disappeared on my server. I would recommend asking your host what you need to set these to in order for their 'garbage collection' routines to clean them up.
Mainio replied on at Permalink Reply
Mainio
One solution to this would also be to simply delete the session files through cron once a day, for example:
0 0 * * * find /home/USERNAME/public_html/files/tmp/sess_* -mtime +0 -exec rm {} \;


This only deletes files that are older than one day.

I've even run to situation where the millions of session files have prevented concrete5 from working because of the /tmp folder being unusable (some file system specific issue with too many files in a dir).
AccountDisabled replied on at Permalink Reply
One of my favorite clients (msanderson) had a site with messy /files/tmp folder. Our solution was to create a concrete5 job to clean up any sess_ files older than a day.

Here is the job file "clean_temp_sessions.php" we created along with install instructions.

<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
/*
Install
    Copy this file to /jobs
    Dashboard > System & Settings > Automated Jobs
    Install "Clean Temp Sessions"
    Automate the job to your liking
*/
class CleanTempSessions extends Job {
    public function getJobName() {
        return t('Clean Temp Sessions');
    }
    public function getJobDescription() {
        return t('Cleans up PHP sess files from /files/tmp that are older than one day.');


Posted with love in case anyone else finds it useful. ^_^

Cheers!
jordif replied on at Permalink Reply
jordif
Thanks, I was looking exactly for this! It works perfectly.

Sorry for the bad pun, but... great job :)

jordi
lota replied on at Permalink Reply
lota
Great! A very useful job!
adwlabs replied on at Permalink Reply
adwlabs
Hi ForestMist,
I have the same problem but I don't know how to use your code.
In particular i didn't understand where I have to put the code.
Please can you help me?

thank you very much
mhawke replied on at Permalink Reply
mhawke
Perhaps I can help. This assumes you are running version 5.6.x.x.

First, have you checked to see if there are a lot of session files inside the /files/tmp folder?

If so, follow these directions to install ForestMist's code:

1) Copy all the lines of code from ForestMist's post to your clipboard. (click the link below it to see all the code)
2) Create a new, blank file in a pure text editor (like Notepad++ or just Notepad) and paste the code into this new file.
3) Save the files as "clean_temp_sessions.php"
4) Upload this new file to your root level /jobs folder
5) Visit "Dashboard->Automated Jobs" and click on 'Install' button next to this new Job (below the existing jobs)
6) Once it installs, click the 'Run' button.

Hope that helps
AccountDisabled replied on at Permalink Reply
Nice instructions mhawke. Thanks. :)
adwlabs replied on at Permalink Reply
adwlabs
Hi mhawke, many thanks for your reply.
I followed your instructions and installed the new job. It works fine.
Unfortunately my problem persists: all files "sess_" in the "tmp" folder have permissions setted on 0600 (adfrw) by default.
So, the new job doesn't clean the folder. I always have to set the permissions on 777 manually, and then I'm unable to delete the files via ftp.
Any suggestion to solve my problem would be appreciated.

Thank you very much
AccountDisabled replied on at Permalink Reply
Usinghttp://php.net/function.chmod in the job to set the permissions on the file before removing it may help. Keyword, may.

For example, you could try the code below. It is the same code as before with the addition of a chmod command right before unlinking of the file.

<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
/*
Install
    Copy this file to /jobs
    Dashboard > System & Settings > Automated Jobs
    Install "Clean Temp Sessions"
    Automate the job to your liking
*/
class CleanTempSessions extends Job {
    public function getJobName() {
        return t('Clean Temp Sessions');
    }
    public function getJobDescription() {
        return t('Cleans up PHP sess files from /files/tmp that are older than one day.');


I have not tested the above code so it may need further refinement by someone actively working with concrete5 (since I am no longer).
enlil replied on at Permalink Reply 1 Attachment
enlil
Just what I was looking for! Took it one step further and put it in package form using forestmist's most recent code. @adwlabs, unzip it, place it in your root packages folder and install it through the dashboard. Haven't tested against any chmod quirks yet, but is working as expected in my environment. Any feedback to make it better is welcome and with forestmist's kindly ok, I'd be happy to push this to the marketplace as a free add-on for broader use. Enjoy. See Attached...
AccountDisabled replied on at Permalink Reply
Please feel free to use the code for whatever you wish. :D
adwlabs replied on at Permalink Reply
adwlabs
thanks to all. I think it was a server problem, because now the automatic process works fine. Many thanks
enlil replied on at Permalink Reply
enlil
This is now available free in the marketplace!
http://www.concrete5.org/marketplace/addons/enlil-sess-files-job/...
AccountDisabled replied on at Permalink Reply
Nice. More people will be able to use it as an installable package. Good job. :D
Floyd112 replied on at Permalink Reply
Just leave it there. Its part of the system files.
enlil replied on at Permalink Reply
enlil
sure, until there's a million of them and your server crashes because theres no disk space left :|
eccw replied on at Permalink Reply
Will this job work with 5.7?
enlil replied on at Permalink Reply
enlil
No it is for 5.6