Jump to content
MakeWebGames

[any version] removal of all crons


MDK666

Recommended Posts

ok as you noticed from the subject that you can remove all crons from the game, this might sound sceptical but stay with me on this one.

instead of using the basic cron jobs or command line as we all use and hate to death well at least i do, but i was reading up on some basic on game design and i came by the idea of a "on-view" method of crons instead of the files. i'm going to try and explain this as best i can on installing this so yea don't get mad if i kinda don't explain it very well for everyone but anyways here goes.

Implementing this in your own database is a trivial change; all you need to do is add a timestamp to the table you need to track times for, and then compare it to the current time. Here’s what an example table might look like

We will start out by creating a new table in your database:

 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

And then all you would need to do in your code is something like this, on every page an authenticated user visits

 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

And that would be essentially all you’d need to do – just check the last time a user’s information was updated, and then update it if it’s been longer than the amount of time you want to update a user’s stats in. Also, if you write your code in such a way that you can just pass in what to update the value with, you can reduce the overhead of using a for() loop as well:

 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

Now, this will allow you to keep large amounts of data updated, without encountering any sorts of timeout issues – and is therefore perfect for making sure that things like player stats update themselves at the proper times. However, there are still some areas where it’s better to use cron.

For example, let’s say that you are building a browsergame where players health regenerates automatically, at a rate of 1 health every 30 minutes. In this game, time passes just like in the real world – every day counts as a ‘year’ in the game. In this situation, you would want to use the “on-view” method to update the player’s health – but a cronjob would be a much better way to update the “year” value every day. The in-gameyear isn’t really linked to a particular player, and it’s a micro-value – something that is only available in a single place. While you could certainly use the “on-view” method to update the year as well, it’s not quite as practical – a simple cronjob can easily keep your year updated for you, with the added benefit of only running as it’s needed – as opposed to every single time a player visits certain pages.

In summary, “on-view” is another way to achieve virtually the same functionality as cron – with a far more reliable way to keep large amounts of data up-to-date when there are many users playing your game. However, there are still places for cron – and both approaches can be used together to provide the best of both worlds.

I hope everyone enjoys this also just a quick reminder i did not code this or take action on saying i have coded this, its just information i have found that could help us all out with the cron issues.

Link to comment
Share on other sites

  • 3 years later...

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