0

I want to remove the PHP7.1 session file frequently, if I don't remove the files the new PHP session is not generating. So I want to set up the cron job to remove the PHP session.

Session files are saving in the path : /var/lib/php/sessions

Help me to set up the cron job. Thanks.

4
  • do you already have a command you use to clean the files? if you type man crontab from command line instructions are there. you edit your roots crontab with sudo crontab -e Sep 20, 2018 at 17:34
  • I don't have any commands to setup the cron. will this work * /30 * * * rm -rf /var/lib/php/sessions/ >>/dev/null ?
    – Linuxian
    Sep 20, 2018 at 17:37
  • you might want to do rm -rf /var/lib/php/sessions/* to be sure that directory doesn't get deleted, but other than that, that looks correct Sep 20, 2018 at 17:43
  • You may want to remove only old sessions, the above will reset active sessions. Use something like find /var/lib/php/sessions -type f -cmin +60 -delete to remove sessions older then 1 hour.
    – Eelke
    Feb 22, 2019 at 9:30

0

You must log in to answer this question.

Browse other questions tagged .