How to execute PHP code periodically in an automatic way

后端 未结 1 1450
醉酒成梦
醉酒成梦 2020-12-03 20:39

I am willing to truncate a table in a MySQL database periodically but I don\'t know how to make the code that does so run in a specific period of time automatically e.g ever

1条回答
  •  有刺的猬
    2020-12-03 20:55

    You have two approaches.

    First is based on cron jobs - your system may automatically call some PHP script every week. See more in Wikipedia article and learn Cron based on examples (I have seen also some interesting tool somewhere on GitHub, but I am unable to find it at the moment).

    The second is to call some task during execution of different script, eg. when you do not have access to crontab. You may eg. store information about executed scripts in the database - if 7 days have passed after last execution, then execute some function / script and save the new timestamp into the database.

    EDIT:

    You said you are on Windows, but there are cron-like solutions also.

    To add scheduled tasks, follow the guidelines from article on Drupal.org.

    You can also run Cron-like software, eg. CRONw - Cron for Windows.

    0 讨论(0)
提交回复
热议问题