Running a PHP script every 5 minutes and avoiding race conditions

后端 未结 5 1284
无人及你
无人及你 2021-01-12 12:13

I have a php script that needs to run once every 5 minutes. Currently I\'m using a cron job to run it (and it works great) but my host only allows a minimum time of 15 minut

5条回答
  •  攒了一身酷
    2021-01-12 12:23

    The answer to whether visitors can start this script is yes. You can run the script when visitors enter a page. You would want to store start time, but also an attribute for whether it is running. This should avoid any possibility of conflict when trying to update your data. I'de also put an additional field for mail warning which you can use if the runtime passes what you would expect as beyond max time. You can then have the script send you a warning email that your script have been running beyond max time. I've personally kept these statuses in databases, but they can also be stored in files.

提交回复
热议问题