我们可以通过PHP脚本配置cron作业的时间间隔吗? [英] Can we configure cron job's time interval through PHP script?
问题描述
我们是否可以通过PHP脚本配置cron作业的时间间隔,以使该时间间隔不应该手动设置,而是通过PHP脚本设置,而不管是数据库时间间隔还是固定时间间隔(而是从PHP代码内部).
预先感谢
Can we configure cron job's time interval through PHP script, so that the time interval should not be set manually, but through a PHP script, whether it takes time interval from Database or fixed (but from within the PHP code).
Thanks in advance
推荐答案
我认为让您的应用程序控制事件的频率而不是cronjob更好.让cronjob每分钟运行您的应用程序的特定操作.例如,该操作然后检查名为cronjobs的数据库表,并运行通过频率编号或时间戳标记为正在运行的作业.
I think it is much better to let your application control the frequency of events instead of the cronjob. Let the cronjob run a certain action of your application every minute. The action then for example checks a database table named cronjobs and runs the jobs marked for running by either a frequency number or a timestamp.
如果您这样做,则可以从任何地方以编程方式添加新作业,例如通过cronjob界面. 该解决方案易于维护,测试和记录.
If you do it like this, you can add new jobs programmatically from everywhere, e.g. via an cronjob interface. The solution is easier to maintain, to test and to document.
这篇关于我们可以通过PHP脚本配置cron作业的时间间隔吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!