I'm working on this game titled "Fortress", located at http://www.joemajewski.com/fortress. Anyways, it's one of those browser-based role-playing games where players build an army and upgrade their stats to get a high ranking on the leaderboard.
Every 30 minutes a cron job is going to execute, which makes some updates. It loops through each player of the game (which will continue to rise naturally over time as more people join), and updates certain stats. It gives everyone 1 extra turn, gives them gold based on their income, food, wood, copper, iron, etc..., plus it updates their ranking.
That's all mumbo-jumbo, I know, but the point is that each player is going to have their own update query. I timed the script with just three members:
execution time with mysql_query() function commented out for the updates: ~ 3.5 ms
execution time with mysql_query() function working properly: ~ 14 ms
It is clearly the update queries that are going to cause my cron job to get very slow once the game has 100+ registered members. I am hoping to have 100 active players within two weeks of the game's launch, but many players create multiple accounts, so I expect at least 200 members after a couple weeks. With 200 update queries, plus the extra time to sort members and calculate rankings, it will likely take over 2 seconds to run the cron job.
My question to you. Is there a faster way to do something like this? I tried adding a "START TRANSACTION" and "COMMIT" queries before and after the loop, respectively, but it's hard to gauge speed with just 3 members. Will transactions make the script better or worse? Any other way around this? Any help would be appreciated.
Thank you very much for taking the time to listen to my plea.