Forum Moderators: coopster

Message Too Old, No Replies

Updates without crons

         

stargateanubis14

1:52 am on Feb 17, 2009 (gmt 0)

10+ Year Member



I have database queries that are set to "go off" according to the time from a unix timestamp.... something like

$timer= time() + (24 * 60 * 60);

This would set a timer for 1 day later.

Without running any server-side cron jobs, is there any way to have an action be performed at that time?

An example:

Here's the situation that runs into my head...

Okay. Someone sets an attack on a building. It is set to happen in 30 minutes, he logs off, and will come back in an hour.
Someone else comes and logs in to another account, 2 seconds later, attacks that troop, with very little HP, and sets the attack to happen in 30 minutes (2 seconds after the other attack should have happened). He leaves and wont come back for an hour.

Now... The person who was attacking the building. Their attack should land right before they are destroyed. But, if no one logs on to witness it, then when either of the 2 players logs on and checks that area, it will be read that the other player was destroyed. Now, even if they log on, and it checks for expired actions first, and performs them in order, what happens if the player views the map so that only the troop attacking the other troop is visible. It will "update" that general screen area, and then the other corresponding troop will die, never finishing the attack.

This goes far beyond just 2 players doing stuff...such as in when trying to get the most up to date # of troops for the player who hasn't been on in ages, and a massive war was waged on them by another person who hasn't been on in ages.... that war will essentially not happen, and their ranks will still be high, because no one was ever there to witness it.
its all theoretical, almost like "if a tree falls in the forest, and no one hears it, does it matter?"...in this case, it does matter...and i need to find a way to "watch" that tree....

coopster

12:37 pm on Feb 17, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



That is what a crontab does :)

If you need to have actions in a database table happen in a particular order the only way to have them applied is to process them in sequence. You can do this with an incremental column or you could use a timestamp column to be your increment. Usually a crontab triggers and processes the table but if you need to do it "on demand" you will have to devise your own logic to process as desired.

stargateanubis14

1:35 pm on Feb 17, 2009 (gmt 0)

10+ Year Member



Crons will be a lot of stress on a server. It would be okay for when there are only a few things going on across the map, but when there are many things happening and being updated (such as every 30 seconds), it is sorta stressing on the server.

I figured that was the easiest way, but i was hoping to find another round-about way of doing it