简体   繁体   中英

PHP garbage collector cronjob to run every 3 hours

PHP Sessions are stored in files. php.ini is configured to consider garbage all the sessions that "are older" (have not been modified) in the last 3 hours. There is a cronjob in /etc/cron.d/php5 which deletes the sessions. It is configured to be run every 30 min and I would like to change it to every hour. How can I modify it? crontab -l command is not listing that cronjob. Why? Thanks

Well, it's not in a crontab, it's in the /etc/cron.d/php5 file. Have a look there. My guess is it will be something like this from my system:

09,39 *     * * *     root   [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2>/dev/null \; -delete

Just modify the times to run every hour instead:

9 * * * * <<the rest here>>

If you have an already running cron job, you can get the user which is running the job by using the following command (need root).

for user in $(cut -f1 -d: /etc/passwd); do echo $user; crontab -u $user -l; done

Once you get the user which is running the job you can just su to that user and use crontab -e to edit the job.

If you don't have any cron job setup already, you can create a new cron job as follows.

  • Login to the user which needs to run the script
  • Run crontab -e (this will bring up the editor)
  • Add you job there.

You can add any of the following command in the editor to setup an hourly cron job.

0 * * * * /path/to/your/script/to/execute

or

@hourly /path/to/your/script/to/execute

Additional info about cron can be found here https://en.wikipedia.org/wiki/Cron

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM