Cron Task – How to Remove Task That Deletes PHP Sessions

cronPHP

It seems Linux Mint 19.3 Tricia Cinnamon wants to clear out PHP session files every half-hour.

How do I:

  • Remove this task from the scheduler's awareness, and
  • Not have to reboot the computer to do so.

I found the crontab file at /etc/cron.d/php.

I edited the file by making the relevant line a comment. I expected that now that there is no information in this crontab file that would establish when it should trigger the task, not even the scheduler(?) would keep aware of it.

# 09,39 *     * * *     root   [ -x /usr/lib/php/sessionclean ] && if [ ! -d /run/systemd/system ]; then /usr/lib/php/sessionclean; fi

The cron process(?) noticed the new file timestamp and reloaded the file (as seen in the syslog).

But the scheduler is still logging in syslog.

Mar  6 01:09:07 BrownBunny systemd[1]: Starting Clean php session files...
Mar  6 01:09:08 BrownBunny systemd[1]: Started Clean php session files.

(which I do not know where to look for those phrases).

I tried the command:

sudo service cron reload

The PHP session files were still cleaned up.

I can move the php crontab file out of cron.d. Considering the above, would this even work?

Notes: I am cross-posting this question from LinuxMint Forums:

Note: This question is copied over from Ask Ubuntu because they consider it not really applicable to Ubuntu.

Best Answer

The phpsessionclean scripts as delivered by upstream Debian will either use cron if there is no systemd present, or will use systemd for scheduling if it is available.

This is apparent in the cronjob test if [ ! -d /run/systemd/system ] which checks if systemd has been initialized on this system.

When systemd is available, phpsessionclean has a service unit (phpsessionclean.service) in addition to a timer unit (phpsessionclean.timer). Stopping and disabling both of these, should stop the scheduled task from running within systemd:

systemctl stop phpsessionclean.service
systemctl disable phpsessionclean.service
systemctl stop phpsessionclean.timer
systemctl disable phpsessionclean.timer
Related Question