Execute scripts later in time
<p>For a personal game I'm working on, I'd like to have a php function work over a certain period of time.</p>

<p>For example, right now it's set so that if the user wishes to purchase soldiers in the game, he fills out the form and when it's submitted, the user's database entry is instantly updated to reflect the change in soldiers.</p>

<p>What I would like is to have a time delay between the form submission and when the soldiers actually appear (to simulate training time, etc.). </p>

<p>I thought of one possible approach, but I hope it isn't the best one. I could create a new database table, "actions" that contains the type of action (i.e. the task to execute, in this case training soldiers), a parameter (the number of soldiers), and the action's start/end times. Whenever the user loads the page, the page checks to see if any actions have been completed and executes them if they are.</p>

<p>The key problem with this is that actions only execute when the user loads the page. He could buy soldiers and have them not appear until whenever he happens to log in, potentially leaving him vulnerable for large amounts of time.</p>

<p>I could resolve this by checking all user's actions whenever anyone loads the page, but I believe this would be unnecessarily taxing on the server, in addition to being fairly difficult to implement.</p>

<p>Does anyone have better ideas, or is my train of thought the best approach there is? Thank you!</p>
