2

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 every week. Do you know any approach or class to do so?

EDIT: I am on windows sever

Mu Mind
  • 10,935
  • 4
  • 38
  • 69
menislici
  • 1,149
  • 5
  • 18
  • 35
  • Use a cron (http://en.wikipedia.org/wiki/Cron). – ComFreek Oct 29 '11 at 15:01
  • Cron is used in linux environments, right? Well, I'm on windows unfortunately... – menislici Oct 29 '11 at 15:04
  • Duplicates: http://stackoverflow.com/questions/4793051/php-mysql-once-a-week-operations && http://stackoverflow.com/questions/4583930/run-php-script-once-in-a-week – Levi Morrison Oct 29 '11 at 15:04
  • http://www.onlinecronservices.com. The most popular services listed there are http://scheduler.codeeffects.com and http://www.crondroid.com/cron/daily –  Oct 30 '11 at 15:30

1 Answers1

11

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.

Tadeck
  • 132,510
  • 28
  • 152
  • 198
  • The URL for "learn Cron based on examples" http://crontranslator.appspot.com/ now shows: *"Python 2.5 is no longer available. Please refer to (URL that Stack won't let me paste) for more information."* - Can you update the answer in order to either remove it or to update it? Edit: You appear to be inactive. – Funk Forty Niner Oct 31 '17 at 11:43