views:

69

answers:

3

We need to create a script (ajax or php or javascript) that will clean some tables from our database at fixed time.

We can not use server features such like Cron tab or others.

Any suggestions??? Thanks

+2  A: 

There are some services out there which allow you to schedule a request for a specified URL remotely (basically allowing another server to run a cron job at a specified time, calling a script on your, internet-accessible, server) such as SetCronJob.com, amongst others (Google for "web cron service").

If you are dealing with a server which is not accessible from the internet (ie on a LAN), then this solution will not be suitable.

Lucanos
A: 

Javascript, if you don't mind having this web page open 24x7: use setTimeout on page load to wait until a set arbitrary time later on during the day when you do cleaning, then call setInterval. setInterval will initially call and regularly repeat a xmlhttprequest or just a page refresh using get or post to pass parameters to the PHP script behind itself.

You may want to consider instead moving a real Cron job to another system within the network to open your PHP page remotely, even setting it up on your own system's Task Scheduler (if Win) or Cron (if else) if need be.

bob_the_destroyer
+1  A: 

You can do a poor mans CRON by tethering the task you need to run to another script that gets run by human interaction. So, for example, when foo.php is done it calls cron.php (synchronously or asynchronously). To limit how often cron.php actually runs (preventing excessive runs) you can store the last timestamp and compare for a certain interval (say, every 600 seconds).

This all, of course, presumes there are humans visiting your site.

Inkspeak