PHP: running scheduled jobs (cron jobs)

前端 未结 13 1753
自闭症患者
自闭症患者 2020-11-22 14:36

I have a site on my webhotel I would like to run some scheduled tasks on. What methods of achieving this would you recommend?

What I’ve thought out so far is having

13条回答
  •  庸人自扰
    2020-11-22 14:53

    If you want to avoid setting up cron jobs and whatnot (though I'd suggest it's a better method), the solution you've provided is pretty good. On a number of projects, I've had the PHP script itself do the check to see whether it's time to run the update.

    The down-side (okay, one of the down sides) is that if no one is using the app during a certain period then the script won't run.

    The up-side is that if no one is using the app during a certain period then the script won't run. The tasks I've got it set up to do are things like "update a cache file", "do a daily backup" and whatnot. If someone isn't using the app, then you aren't going to need updated cache files, nor are there going to be any database changes to backup.

    The only modification to your method which I'd suggest is that you only run those checks when someone successfully logs in. You don't need to check on every page load.

提交回复
热议问题