Forum Moderators: coopster

Message Too Old, No Replies

Mysql Truncates

         

msmtrimm

9:05 pm on Dec 21, 2004 (gmt 0)

10+ Year Member



Um, does anyone know how to create a page that every 15 minutes it will truncate a database table, then every 10 seconds add a value to the table?

StupidScript

10:13 pm on Dec 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



use a "cron job" to execute the program you will write to accomplish the truncate/insert, on a Unix/Linux server.

msmtrimm

4:39 pm on Dec 28, 2004 (gmt 0)

10+ Year Member



a cron job, don't know anything about them.

RonPK

4:55 pm on Dec 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A cron job is a task that runs with a set interval. Try Google ;) The minimum interval is 1 minute, so maybe you'll need another solution.

sleep(10) [php.net] may be of use, if you can get the script to run forever. You'll either have to call it over HTTP, with a browser, or run it from the command line, if your PHP is configured to do so.

dmorison

5:05 pm on Dec 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As Ron says, cron has a maximum resolution of 1 minute.

So, given that you have a requirement to truncate the table every 15 minutes, you could schedule a cron job on 15 minute intervals that first does the truncate, then does the 10 second updates for the next 14 minutes and 50 seconds, then exits.

There are a number of threads here about using PHP with cron - this one for starters:
[webmasterworld.com...]
(search to find plenty more).

How accurately do you need to hit the 10 second mark? sleep(10) could work, but if you need to be really accurate this needs to be thought over carefully as you don't want to clobber system resources! A loop forever checking time() would be a bad idea unless your box has nothing else to do..!