time - Running a PHP script or function at an exact point in the future -


i'm working on browser game php backend needs perform checks @ specific, changing points in future. cron jobs don't cut me need precision @ level of seconds. here's background information:

  • the game multiplayer , turn-based
  • on creation of game room game creator can specify maximum amount of time taken per action (30 seconds - 24 hours)

once player performs action, should have specified amount of time perform next, or turn goes player next in line.

for obvious reasons can't keep track of time through javascript, far easy manipulate. can't schedule cron job every minute may 30 seconds late.

what efficient way tackle problem? can't imagine querying database every second server-friendly, direction leaning towards[1].

any or feedback appreciated!

[1]:

  • a user makes move
  • a php function called sets 'switchturntime' in mysql table's game row 'timestamp'
  • a php script running in background queries table games 'switchturntime' has passed, switches turn , resets time.

you can use queue or daemon. works if have shell access server.

https://stackoverflow.com/a/858924/890975

every time need action occur @ specific time, add queue delay. i've used beanstalkd varying levels of success.

you have lots of options way. here's 2 examples 6 second intervals:

  • use cron job every minute add 10 jobs, each delay of 6 seconds
  • write simple php script runs in background (daemon) adds new job queue every 6 seconds

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -