Modx_session table

Hi there,

I had a site on my server which was running low on disk space.
It’s a small site, so but investigating, I found it was the database which was taking up 1.4GB.

The table causing this was Modx_session

I have logged out all users, which clears the table down, but I don’t understand why it’s growing so large.

I have several sites on the same server - all of which have similar traffic - but the Modx_session table is only 50MB or so.

The only difference I can see is the site in question has ben ‘hardened’ in terms of security - so the Core folder is above the main public_html folder.

Could this be the reason why the sessions table isn’t being emptied?

Thanks in advance for any help.

Andy

What’s the value of the system setting session_gc_maxlifetime? Maybe you can lower that value.

Thanks Harry - yeah I could do, but it’s the default value:

806400

Which is only a week (if my maths are correct!) so I can only assume that the sessions aren’t being flushed after that time for some reason.

You could check the column “access” in the modx_session table. What’s the smallest value?

Right - Presumably this is to see how old the oldest session is?
Well I guess I was a bit stupid - because I flused the tale manually already - but this is the smallest value in there now:

1633940740

But if that value relates to the ages of the session that that doesn’t help as it was flushed this morning. Doh…

Yes, now you have to wait a week to see if the garbage collection works. :wink:

hmm - dammit - will report back this time bext week!!! :laughing:

just strange how it’s only this site and no others that are doing this.

That’s common, about 1 in 3 sites in SiteDash have that and that’s why that has a remote session clearing functionality :wink:

The root cause is the server is optimized to not run the garbage collector normally, but through a cron job. However MODX doesn’t store sessions in the default location, but in the database, which that cron doesn’t know about.

To fix it the PHP.ini setting session.gc_probability needs to be set back to 1 instead of 0. Or connect the site to SiteDash.

1 Like

Thanks Mark.
I don’t have an php.ini file in the site directory (it’s just using default settings from the server) so I have added one with just that setting. Will see if that works - thanks!

Just as a comment and as a solution in my case, I found the same problem on a website that was upgraded to ModX3.

The problem was a setting: session_handler_class

That needs to be set to: MODX\Revolution\modSessionHandler

After that just click on the left column Manage/Logout all users it will clear the modx_session table.

Hope that helps, cheers!

1 Like