Razor42 Posted August 19, 2013 Posted August 19, 2013 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 Quote
KyleMassacre Posted August 19, 2013 Posted August 19, 2013 Timestamps would be the best way to go in my opinion Quote
sniko Posted August 19, 2013 Posted August 19, 2013 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 PHPThe 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 :) Quote
Razor42 Posted August 19, 2013 Author Posted August 19, 2013 The current times span from 5 -300 seconds. Also there will be an option to boost the time to 0 with "medals". Would either option affect this? Quote
Dayo Posted August 19, 2013 Posted August 19, 2013 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'; } Quote
Dave Posted August 19, 2013 Posted August 19, 2013 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. Quote
Razor42 Posted August 19, 2013 Author Posted August 19, 2013 Thanks guys! Really appreciate the help! Quote
Razor42 Posted August 20, 2013 Author Posted August 20, 2013 Have sorted this issue and the timezone works perfect!! Thanks guys! Quote
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.