MasterACE14 Posted October 7, 2007 Author Share Posted October 7, 2007 how did I miss that? lol *bashes head on wall* thats in the database now, but the timer isn't working correctly. I echo it and it displays Next Turn in 19862234 min It should be 59 minutes or less. So I don't know :-\ Quote Link to comment https://forums.phpfreaks.com/topic/71794-cronjob-and-timer/page/2/#findComment-363804 Share on other sites More sharing options...
MasterACE14 Posted October 7, 2007 Author Share Posted October 7, 2007 anyone got any ideas? I've written it all over again here: http://www.phpfreaks.com/forums/index.php/topic,161819.45.html for anyone who has just started reading this thread. Quote Link to comment https://forums.phpfreaks.com/topic/71794-cronjob-and-timer/page/2/#findComment-363919 Share on other sites More sharing options...
yzerman Posted October 7, 2007 Share Posted October 7, 2007 Is your time in stored in unix format or is it stored in 2007-10-06 0540 format? Quote Link to comment https://forums.phpfreaks.com/topic/71794-cronjob-and-timer/page/2/#findComment-363924 Share on other sites More sharing options...
MasterACE14 Posted October 7, 2007 Author Share Posted October 7, 2007 its stored as an integer, I guess thats the problem then? Quote Link to comment https://forums.phpfreaks.com/topic/71794-cronjob-and-timer/page/2/#findComment-363926 Share on other sites More sharing options...
AndyB Posted October 7, 2007 Share Posted October 7, 2007 yes lol, I knew someone would say that , the point of it is, its for my text game, and players need to know when the next "turn change"(cronjob) will be. So they can workout the best time to attack their enemies etc. Perhaps I'm missing the whole point here, but if your cron job runs every hour and the present time is 34 minutes past the hour isn't the next cron job in 26 minutes? Why is this problem more complex than that? Quote Link to comment https://forums.phpfreaks.com/topic/71794-cronjob-and-timer/page/2/#findComment-363928 Share on other sites More sharing options...
yzerman Posted October 7, 2007 Share Posted October 7, 2007 if its stored as an integer - then you need to pull it from the database as an integer, and print it out in date format. so if you pulled it from the database and stored it in the variable $lasttime: <?php $lastrun = date("H:i", $lasttime); // this will output the last time the cron was run as 06:24 instead of an integer //now you want to know how much time until the next cron is run $nextrun = mktime(date("H",$lasttime)+1); //this adds 1 hour to the last time the cron was run, outputting 07:24 ?> Quote Link to comment https://forums.phpfreaks.com/topic/71794-cronjob-and-timer/page/2/#findComment-363935 Share on other sites More sharing options...
MasterACE14 Posted October 7, 2007 Author Share Posted October 7, 2007 point taken, is it possible to do this, just with the current time? workout how long until the next hour, and workout how long it has been since the last one? That sounds like a better idea, then what I've currently been doing. here's what I've done to get the current time in my timezone: <?php $date=date(U); // format date for calculation in seconds //print ("$date"); //if you want to see the date format now $hourdiff = "16"; //change the server time plus sixteen hours $timeadjust = ($hourdiff * 60 * 60); //this is how to calc it $adjtime = date("M j, H:i", $date + $timeadjust); //format display print $adjtime; //print the adjusted time now if I could workout the time differences just by adding onto this script, I think that would be great. Quote Link to comment https://forums.phpfreaks.com/topic/71794-cronjob-and-timer/page/2/#findComment-363941 Share on other sites More sharing options...
yzerman Posted October 7, 2007 Share Posted October 7, 2007 <?php $lasttime = '1191759840'; $lastrun = date("H:i", $lasttime); // this will output the last time the cron was run as 06:24 instead of an integer //now you want to know how much time until the next cron is run $nextrun = date($lasttime)+3600; $nextruntime = date("H:i", $nextrun); //this adds 1 hour to the last time the cron was run, outputting 07:24 $countdown = $nextrun - time(); $countdownmins = round($countdown/60, 1); echo "last turn was at $lastrun, the next run will be at $nextruntime, the time remaining until next run is in $countdownmins Minutes"; ?> Try something like this. Quote Link to comment https://forums.phpfreaks.com/topic/71794-cronjob-and-timer/page/2/#findComment-363967 Share on other sites More sharing options...
MasterACE14 Posted October 7, 2007 Author Share Posted October 7, 2007 That seems to be working great , I'm going to let it run through for about the next 8 hours to make sure the cronjob is running on time and that the timer script isn't stuffing up EDIT: I noticed that working out the next run and last run, it is displaying the time at the location of my Web Host, how could I change it to my time, which is what my date script above does. ? thanks for your help yzerman and everyone else who helped me with this matter. Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/71794-cronjob-and-timer/page/2/#findComment-364010 Share on other sites More sharing options...
MasterACE14 Posted October 8, 2007 Author Share Posted October 8, 2007 I'm starting to get some strange results, The timer works fine for a few turns, say 4 turns, and then after the 4th turn it says something like 120 minutes until the next one. I have to manually run the cron file then to make it go back to "60 minutes until next turn". Quote Link to comment https://forums.phpfreaks.com/topic/71794-cronjob-and-timer/page/2/#findComment-364539 Share on other sites More sharing options...
MasterACE14 Posted October 8, 2007 Author Share Posted October 8, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/71794-cronjob-and-timer/page/2/#findComment-364576 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.