Jump to content

Auto-Refresh SQL?


Medicine

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.