cron jobs or PHP scheduler

后端 未结 6 1776
星月不相逢
星月不相逢 2020-12-01 22:32

I am using MYSQL as my database and PHP as my programming language.I wanted to run a cron job which would run until the current system date matches the \"deadline(date)\" co

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 23:18

    While CRON and Windows Scheduled Tasks are the tried and true ways of scheduling jobs/tasks to run on a regular basis, there are use cases where having a different scheduled task in CRON/Windows can become tedious. Namely when you want to let users schedule things to run, or for instances where you prefer simplicity/maintainability/portability/etc or all of the above.

    In cases where I prefer to not use CRON/Windows for scheduled tasks, I build into the application a task scheduling system. This still requires 1 CRON job or Windows Task to be scheduled. The idea is to store Job details in the database (job name, job properties, last run time, run interval, anything else that is important for your implementation). You then schedule a "Master" job in CRON or Windows which handles running all of your other jobs for you. You'll need this master job to run at least as often as your shortest interval; if you want to be able to schedule jobs that run every minute the master job needs to run every minute.

    You can then launch each scheduled job in the background from PHP with minimal effort (if you want). In memory constrained systems you can monitor memory usage or keep track of the PIDs (various methods) and limit to N jobs running at a given time.

    I've had a great deal of success with this method, YMMV however based on your needs and your implementation.

提交回复
热议问题