   [web] PHP MMO Time-Passing
  I plan on making a PHP MMO.  I've got a fair bit of experience.One thing baffles me though: time refreshing.  Take a game like Utopia.  Every x minutes/hours (typically every 24 hours), time "moves forward".  Things get built.  Resources incremented.  Research advances.  Armies battle.How on earth do you code THAT part?  I suspect it has something to do with timed actions ("chron jobs" or "scheduled tasks"), but I'm not sure.Any insight would be appreciated.   
  You'll need some kind of database on your server to keep track of all the objects in the world. When the page refreshes you find out how long ago the building was first put in to construction, after a certain amount of time has passed you show a different stage of construction and eventually you show a finished building.In a nutshell thats how that would all work out. Keep track of everything and have objects show with different images as time goes by.;  In other words, it's refresh-on-demand?  As in, when you log in, it updates your stuff?Assume: Utopia-style game.Hmm.  But what if you don't log in for, say, 48 hours, and in the meantime, you're attacked 3 times?  The server has to update your info after every attack, so the players can gauge you properly in subsequent attacks.That either implies instantenous attack results, or a global "time will move forward at midnight GMT" style, which I assumed from the start.   ;  When a friend of mine made his own Utopia-clone, he simply added a scheduled task that opened a web browser to his special "refresh" page every 24 hours. At least it's a simple solution.   ;  That's pretty cool--I was thinking batch files/scripting, but this would be FAR more elegant.The interesting thing about the on-demand approach is that you don't waste resources updating accounts for people who never log in, and it spreads out the CPU usage over time.  Fascinating.  But it doesn't really allow for multiple interactions.   ;  You're looking for a cron job (*nix) or a scheduled task (Windows).  Basically it executes your script every X hours, minutes, days, whatever.  In this case, your script would subtract time from remaining build time, move armies across lands, etc. etc.   ;  Still go with a refresh on demand, this goes even for attacking. If someone is set to attack someone else that has not been on in a while, you refresh that person then, and continue on with the attack. No scheduled tasks needed for this.   ;  I personally use chron jobs.  The problem I ran across by doing an auto update (ie, on demand) was that I ended up doing it more often than if I just updated everyones account on the hour.  So...  be sure to look at all the advantages/disadvantages before you put a whole lot of effort into coding.   ;  Linux: cronWindows: Task Scheduler   ;  I guess it depends entirely on the dynamics of the game.  I should probably compute the worst-case number of refreshes per day and see if it exceeds the auto one-hour refresh style...On demand definitely makes more sense, efficiency-wise.   