-2

my question is the folowing:

I want to create a browsergame, a bit like grepolis, travian, tribal wars... To do that, i need to modify some values in a database each ten seconds. I was thinking of a server-sided batch file that executes a php script to accomplish my needs, but I don't know how. I have searched on many forums, but they always end up with a CRON job, which is not an option. I hope someone can tell me where to start.

Burkhard
  • 14,596
  • 22
  • 87
  • 108
Zeno Dhaene
  • 3
  • 1
  • 2
  • 3
    why is a CRON job not an option? – cmorrissey Aug 27 '14 at 14:26
  • 5
    You do *not* have to do something every 10 seconds. You can/should/need to write your game logic so any state can be derived at any time. If someone is supposed to get a new piece of gold every minute or so, all you need to do is save a timestamp, how much gold the user had at that time, and then the next time he opens the page calculate the time difference and add the gold he should have acquired in the meantime. – deceze Aug 27 '14 at 14:28
  • a cron job in windows can only be executed once every 5 minutes. that is too long. also, i have read that no hosting company accepts cron jobs every 5 minutes – Zeno Dhaene Aug 27 '14 at 14:29
  • 2
    unix cron has a 1 minute granularity anyways. you'd have to run 6 jobs, and have 5 of them sleep for 10/20/30/40/50 seconds anyways. like @deceze said, if all you're doing is incrementing a number, then use time-based calculations to figure out how big that number should be when the new value is needed. – Marc B Aug 27 '14 at 14:30
  • @deceze: thanks! didnt thought of that! but than there is another problem that i have: i want to let the page refresh every 10 seconds or so. can that be achieved or is it better not to do that? – Zeno Dhaene Aug 27 '14 at 14:31
  • Refreshing a page is a client side operation anyway. Simply trigger a page refresh via Javascript, which will trigger a PHP request, which triggers a recalculation of the current state as explained above. Of course, doing the whole thing via AJAX instead of a page refresh would be much nicer... – deceze Aug 27 '14 at 14:36
  • okay then! thanks everyone! this answered my question: where should i start – Zeno Dhaene Aug 27 '14 at 14:49

1 Answers1

0

if you are using mysql as I see with your tag, try using Event Scheduler

for example of usage look at this answer

Community
  • 1
  • 1
AlexGreg
  • 838
  • 10
  • 22