gamble Posted April 3, 2014 Share Posted April 3, 2014 (edited) Just a quick questions for you guys: Would you use cronless crons in your game if they were available? Meaning the crons dont use the usual cpanel cron job functions but a file that is called when users are active to credit them that way. I believe a user on the forums released a MCC version. Sorry about the god awful explanation haha. Cronless cron by MTG: http://magictallguy.tk/mods.php?mod=20 Edited April 3, 2014 by gamble Quote Link to comment Share on other sites More sharing options...
SRB Posted April 3, 2014 Share Posted April 3, 2014 You mean; "Would you remove crons and work from timestamps?" Quite easy to just work from timestamps, as long as you write it correctly and think thoroughly about where to activate updates. Can be a long task to completely remove them though. Replacing a cron with a cron, however, doesn't make much sense, since you would have to run more resources to check if it's due to run on all active players. That's an extra query, per player, every page load, to check the files. May as well just let the system run it once on command. Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted April 3, 2014 Share Posted April 3, 2014 I vote Yes. When I develop a module I try and steer away from using crone and use timestamps. I feel it's just better to perform transactions incrementally and doing only what needs to be done instead of for example when 00:00:00 hits I run 1 min cron, 5 min cron, 1 hour cron, and 1 day cron. I think crons from the cron tab should be used mainly for large transaction like generating reports, backups, etc Quote Link to comment Share on other sites More sharing options...
gamble Posted April 3, 2014 Author Share Posted April 3, 2014 OP update to show what i mean... Quote Link to comment Share on other sites More sharing options...
lucky3809 Posted April 3, 2014 Share Posted April 3, 2014 depending what is being updated, timestamps may be suitable for it rather than a command. I use both, but timestamps in my opinion works better. Quote Link to comment Share on other sites More sharing options...
Guest Posted April 3, 2014 Share Posted April 3, 2014 No, sure timestamps for some things, however I have around 40 crons running various automated tasks to manage the game so :). With MCCodes I would still use crons :) Quote Link to comment Share on other sites More sharing options...
sniko Posted April 3, 2014 Share Posted April 3, 2014 No, sure timestamps for some things, however I have around 40 crons running various automated tasks to manage the game so :). With MCCodes I would still use crons :) Reiterating. Quote Link to comment Share on other sites More sharing options...
Djkanna Posted April 3, 2014 Share Posted April 3, 2014 (edited) Dependent on the tasks the cron is required to do. Things like stat updating and such, sure. [get last run info] -> [calculate how many times it should have run between now and then] -> [alter values dependent on the value of the calculation] -> updates -> set new last run info. Things that explicitly need to run a set time, no. *Haven't tested "cron-less crons" *facepalm* in a live environment, so unable to comment in that respect. Edited April 3, 2014 by Djkanna Quote Link to comment Share on other sites More sharing options...
gamble Posted April 3, 2014 Author Share Posted April 3, 2014 Thanks for the responses so far guys! It is interesting to see the way you guys propose the use of them and reasons for it or reasons not to use it. Quote Link to comment Share on other sites More sharing options...
Alan Posted April 3, 2014 Share Posted April 3, 2014 Certainly not. The author of said cronless crons really missed the point, and failed to address several issues relating to how periodic events are triggered. Consider writing more sane code, that does not rely on periodics, it's not difficult. Quote Link to comment Share on other sites More sharing options...
gamble Posted April 3, 2014 Author Share Posted April 3, 2014 Certainly not. The author of said cronless crons really missed the point, and failed to address several issues relating to how periodic events are triggered. Consider writing more sane code, that does not rely on periodics, it's not difficult. I am by no means talking MTG's cronless crons...i talking the general idea of them. Quote Link to comment Share on other sites More sharing options...
lucky3809 Posted April 4, 2014 Share Posted April 4, 2014 Should be rephrased, timestamps vs cronjobs.... timestamps are good for things like education mods, or mods that have a waiting period;jail,hospital,ban, but for bars and things that update more frequently for ALL players at once should use cronjobs for them... This is only my opinion though. Quote Link to comment Share on other sites More sharing options...
SRB Posted April 4, 2014 Share Posted April 4, 2014 Should be rephrased, timestamps vs cronjobs.... timestamps are good for things like education mods, or mods that have a waiting period;jail,hospital,ban, but for bars and things that update more frequently for ALL players at once should use cronjobs for them... This is only my opinion though. I kind of like the term. It's growing on me. It's like; A chicken free, chicken and mushroom pie. A non-chocolate, chocolate teapot. Or even a sugar free, sugar cube. Oxymorons, indeed. Quote Link to comment Share on other sites More sharing options...
Veramys Posted April 4, 2014 Share Posted April 4, 2014 I use timestamps to run 1 and 5 minute stuff. I use Crons to run hour and day stuff. I could switch solely over to timestamps but really I don't want to. Quote Link to comment Share on other sites More sharing options...
gamble Posted April 4, 2014 Author Share Posted April 4, 2014 I use timestamps to run 1 and 5 minute stuff. I use Crons to run hour and day stuff. I could switch solely over to timestamps but really I don't want to. Why do you use them for the smaller intervals and not for the bigger ones? Why dont you want to switch completely? Quote Link to comment Share on other sites More sharing options...
Veramys Posted April 4, 2014 Share Posted April 4, 2014 I started using time stamps because the server I was on didn't accept cron jobs for 1 and 5 minute. I never switched after because it wasn't an issue. Still isn't. I like the cron for the hour and day because unless the server goes down or something like that I know they'll run. And if they don't then I'll get an email telling me and I can manually run it. Quote Link to comment Share on other sites More sharing options...
Alan Posted April 4, 2014 Share Posted April 4, 2014 @Guest ... or well-written, high-quality, fast, stable PHP code? :D @gamble, My apologies, conceptually doing away with crons is a good thing as they put undue strain on the server often at highly inconvenient times (anybody remember Torn's daily downtime @ new day? - insane). There are a few commercial applications out there; WoltLab's Burning Board IIRC for one; that runs "crons" from PHP doing away with system-level crons, but I'm far more in favor of a solution based on timestamps triggered only when needed. Crons for system level tasks are usually fine, though care must be taken not to run too much at one time (often midnight). Quote Link to comment Share on other sites More sharing options...
gamble Posted April 4, 2014 Author Share Posted April 4, 2014 @Guest ... or well-written, high-quality, fast, stable PHP code? :D @gamble, My apologies, conceptually doing away with crons is a good thing as they put undue strain on the server often at highly inconvenient times (anybody remember Torn's daily downtime @ new day? - insane). There are a few commercial applications out there; WoltLab's Burning Board IIRC for one; that runs "crons" from PHP doing away with system-level crons, but I'm far more in favor of a solution based on timestamps triggered only when needed. Crons for system level tasks are usually fine, though care must be taken not to run too much at one time (often midnight). Thanks for the post! I would be interested in looking into a "complex" timestamp sort of cron system. I found MTG's quite interesting and am thinking about adding something similar into my current project. This may sound childish or "noobish" but i never really thought about a timestamp approach until i saw MTG's MCC mod. Quote Link to comment Share on other sites More sharing options...
Magictallguy Posted April 10, 2014 Share Posted April 10, 2014 Naturally, I use MySQL Events. Unfortunately, not every host allows you to do this by default. Enabling the event scheduler can be quite the arse if your host doesn't like it. However, as I host my own sites, I don't need to worry about that and will continue to use MySQL Events until something better is written to replace them Quote Link to comment Share on other sites More sharing options...
wrux Posted April 23, 2014 Share Posted April 23, 2014 Why does this need to be done using a cronjob anyway? In your user model just create a method called update_data or something, add a datetime field for your last data update and do something like this (not actual code) for a 5 min update for example: $date_difference = now - last_update; $diff_in_mins = $date_difference.to_seconds; $updates = floor($diff_in_mins/5); if($updates > 1): $energy_increase = $user->is_donator ? 10 : 5; // update the stuff here $this->energy = ($updates * $energy_increase) + $this->energy > $this->energy_max ? $this->energy_max : ($updates * $energy_increase) + $this->energy > $this->energy_max; // update the last updated field $this->update = correct_last_update endif; Quote Link to comment Share on other sites More sharing options...
sniko Posted April 23, 2014 Share Posted April 23, 2014 Why does this need to be done using a cronjob anyway? In your user model just create a method called update_data or something, add a datetime field for your last data update and do something like this (not actual code) for a 5 min update for example: $date_difference = now - last_update; $diff_in_mins = $date_difference.to_seconds; $updates = floor($diff_in_mins/5); if($updates > 1): $energy_increase = $user->is_donator ? 10 : 5; // update the stuff here $this->energy = ($updates * $energy_increase) + $this->energy > $this->energy_max ? $this->energy_max : ($updates * $energy_increase) + $this->energy > $this->energy_max; // update the last updated field $this->update = correct_last_update endif; Because this will just update that 1 player, unless the SQL query (which you haven't provided) updates all players. A cron would be a good way to go, because on every page click we're not adding another query to perform. (35 active players * 5 clicks every 20 seconds = 2,100 added queries a minute.) Quote Link to comment Share on other sites More sharing options...
wrux Posted April 23, 2014 Share Posted April 23, 2014 Because this will just update that 1 player, unless the SQL query (which you haven't provided) updates all players. A cron would be a good way to go, because on every page click we're not adding another query to perform. (35 active players * 5 clicks every 20 seconds = 2,100 added queries a minute.) If you had a very large number of players and incremented them every X minutes you'd experience some server problems. What if you only updated that user only where it is required. Think about the instances where the info for that user needs to be changed, it certainly isn't every 5 or so minutes; - When you are attacking the user update them (hp needs to update maybe) - When you are active so every page load - Any other user interaction, maybe something like for an organised crime? Quote Link to comment Share on other sites More sharing options...
sniko Posted April 23, 2014 Share Posted April 23, 2014 (edited) If you had a very large number of players and incremented them every X minutes you'd experience some server problems. What if you only updated that user only where it is required. Think about the instances where the info for that user needs to be changed, it certainly isn't every 5 or so minutes; - When you are attacking the user update them (hp needs to update maybe) - When you are active so every page load - Any other user interaction, maybe something like for an organised crime? ... and you'd store the last time the "cronless cron" ran in the database, right? I think we may be talking about different things? Edited April 23, 2014 by sniko Quote Link to comment Share on other sites More sharing options...
wrux Posted April 23, 2014 Share Posted April 23, 2014 ... and you'd store the last time the "cronless cron" ran in the database, right? I think we may be talking about different things? Yea I think so, from what I saw the cronless cron idea just updates the entire db when someone loads up a page. I was saying you only need to update what is relevant which would cut the server load down massively Quote Link to comment Share on other sites More sharing options...
sniko Posted April 23, 2014 Share Posted April 23, 2014 Yea I think so, from what I saw the cronless cron idea just updates the entire db when someone loads up a page. I was saying you only need to update what is relevant which would cut the server load down massively Ah, we are talking about different things - kind of. The idea of cronless crons - in this instance - was to update all player and other related stuff typically every minute, five minutes, every hour, every day, IIRC. Quote Link to comment 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.