Jump to content
MakeWebGames

Recommended Posts

Posted

Hi there,

For the current feature I am coding people will be able to recruit soldiers and there will be a set recruit time on the soldier which it will take to recruit the soldier. This time will be measured in seconds. I am wondering if their is any way in which I can create a cron which runs down in seconds for this feature? As there will also be quite a few other features that will be required to run down in seconds aswell or would I be better using timestamps or what?

Thanks in advance,

Razor42

Posted

Depending on the length. (1 day can still be measured in seconds, so you're not being overly specific).

Say the time is 2 seconds, or something equivalent to a minor duration;

  • Put time period in a session
  • Match it to current time, using PHP
    • The time period will be stored in a session using PHP, so timezones won't apply

    [*]If the time period is still active (i.e: session time is greater than current time), don't execute the recruitment

 

Say the time is a few minutes (5, or perhaps even more)

  • Use timestamps ('cron'-way, or session way, entirely up to you)

 

Say the time is a few hours, or above

  • Use servers automatic tasks; crons

 

:)

Posted

to do what you want you would have to run a cron every second! it would be much easier to use a timestamp

i.e.

// When updating the DB
$newts = time()+5; // 5 second wait

$db->query("UPDATE `userstats` SET `newwait`=$newts WHERE id=$userid");


//then when checking run this code
if (time()<$ir['newwait']) {
   echo 'You have to wait for '.($ir['newwait']-time()).' seconds';
}
Posted

Realistically I would strive to never have a cron running under 30 minutes.

Definitely use timestamps for something like this, means you can print out the exact number of seconds until the event happens as well.

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.   Paste as plain text instead

  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...