Medicine Posted February 22, 2012 Share Posted February 22, 2012 Hi all, I am having some trouble with a part of code. Basically the code is set for a Factory to produce 750 items every 30 minutes. It does this fine IF AND ONLY IF someone clicks the Factory page. For example, it produces 750 bullets, then I leave the page alone for say 20 minutes, but when I click back, it doesn't have 10 minutes left before the next produce. Instead, It has 30 minutes. So it only produces when someone on the game clicks the page. I have tried the basic html refresh but that doesn't work. Any idea's? Thanks in advance Quote Link to comment Share on other sites More sharing options...
premiso Posted February 22, 2012 Share Posted February 22, 2012 Is a cronjob (linux) or schedule task (windows) an option? If it is a linux server, and you can setup a cronjob, you can have the cron call the link using curl or wget, and just use their silent triggers to disregard the data. If that is not an option, you can setup a cron or scheduled task on your box to run and call the page every x minutes. That seems to be what you are after at any rate. Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 23, 2012 Share Posted February 23, 2012 There's another option, but it may or may not fit your needs. If your scenario really is about producing units in a time period you probably want to have an inventory of them to do other things with (sell, use or otherwise reduce inventory). But, if your example above is not really accurate and you are only looking for total units generated since a certain time you could simply set the time that production started and dynamically calculate the total whenever you need to. For example, if you set the start of production using a timestamp you could calculate the total production at any time using the following process: //This value would be set/saved when production was supposed to have started //Retrieve it whenever you need to know the current total production $production_start; //Set the time period (in seconds) that production takes $production_cycle = 30 * 60; //30 minutes //Set the units per production period $units_per_cycle = 750; //calculate the total production of units at the current time $total_units_produced = floor((time()-$production_start)/$production_cycle) * $units_per_cycle; If cron/scheduled tasks are not an option and you need to do inventory as well, you *could* use the method above but it wouldn't be idea. You could either update the inventory with new production amounts by checking when the last update was (on a page load) and seeing if any new production was done. If so, update the inventory with the newly produced quantities. OR, don't add to the inventory. Instead always use the calculated value and only store deductions from inventory. The whole downside to this is if you want to change production levels or other criteria change. It becomes a headache trying to keep it all in line. Quote Link to comment Share on other sites More sharing options...
mikosiko Posted February 23, 2012 Share Posted February 23, 2012 @Medicine: other option that also may or may not fit You can explore MySql EVENTS and validate if it fit or not your scenario http://dev.mysql.com/doc/refman/5.1/en/events.html Quote Link to comment Share on other sites More sharing options...
Medicine Posted February 23, 2012 Author Share Posted February 23, 2012 Thanks for the reply's, I'll explain in more details. It's a game, with factories in 7 countries, which produce 750 items every 30 minutes. But it only produces when someone clicks the factory page, if I set a cron job for that page, will it do it for every country? If you get what i mean? Thanks again Quote Link to comment Share on other sites More sharing options...
Medicine Posted February 23, 2012 Author Share Posted February 23, 2012 BTW I've never run a Cron Job either, so any help on how to set it up so that the page runs every 30 minutes would be helpfull, thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.