There is already a cron to clean PHP session, but it doesn't work, why?

I’m having trouble cleaning PHP sessions and understanding why the garbage collector is not working automatically. Then I saw that the problem is that the session.save_path is set (by default of CyberPanel) and so the collector doesn’t work.

So I’m looking at CRON to create a cleaner, but I realized that there is already a CRON there, but it doesn’t work, why?

/usr/local/CyberCP/bin/cleansessions

image

Does anyone have a good solution for this session issue?

To clarify, the garbage collector does not clean automatically and sessions are stored infinitively, leaving my server with no available inodes and giving error 500.

1 Like

Hi,
Changing /usr/local/CyberCP/bin/cleansessions file content with this solved my problem:

#!/bin/bash
for version in $(ls /usr/local/lsws|grep lsphp); do echo ""; echo "PHP $version"; session_time=$(($(/usr/local/lsws/${version}/bin/php -i |grep -Ei 'session.gc_maxlifetime'| grep -Eo "[[:digit:]]+"|sort -u) / 60)); find -O3 "/var/lib/lsphp/session/${version}" -ignore_readdir_race -depth -mindepth 1 -name 'sess_*' -type f -cmin +"${session_time}" -delete; done