Jump to content
MakeWebGames

Crons VS. Time Stamp


AlabamaHit

Recommended Posts

I'm starting this cause I'm curious on everyones opionon on this.

The topic is...

Crons

vs

Time Stamp

====================

What do you think is fastest? For a website that is?...

Please explain your reason behind answer also...

What it is basically do you think that using crons would be faster than blacking

a user with a Time Stamp......

 

Also please post your comments on if you think Time Stamp Won't work.

====================

My Answer..

I would say that Time Stamp is faster..

1. There are not alot of queries running on a page. That has to run every min.

2. It would stop queries from running when there is no users online...Like only updateing users online.

3. umm....stopping alot of usless queries...

4. Less queries running has to mean a faster site? Right?

-------------------------

My Cons......

1. Code would be a little harder...

 

Well thats the only bad thing i can see...

Please post your thoughts.

Link to comment
Share on other sites

Guest Anonymous

Re: Crons VS. Time Stamp

Personally, I run the timestamp method almost 100% across the board, although certain maintenance tasks I still run from crons - garbage collection, but even those only run a couple of times a week at the outside and they will only run if the system is not under too much load.

No need to update all users online either, just perform the relevant regeneration when and where you need to - ie when the user requests a page.

Of course you may have to regenerate their data and perhaps an opponents data during combat, but as you know both parties involved it's simple enough.

Crons can cause terrible lag, esp when you have a lot of users so you get a speed advantage. The code for handling of timestamps may at first seem more complex, however it is far better at ensuring data integrity, (unless of course you are using transactions throughout).

Link to comment
Share on other sites

Re: Crons VS. Time Stamp

For things like updating a user's energy or health, I'm not a big fan of using timestamps for that.

Suppose a user's health goes down to 0, and they don't log in for a day, their health will stay low and they would not be attackable for a long time.

If everytime a user tries to attack someone, you're performing calculations to determine if they need a health update, that could result in more cpu usage than just updating everyone at five minute intervals (which is one query vs however many get run using the timestamp method there)

IMHO, getting rid of the one minute cron is highly essential, 5 minute crons and up, the returns on that might not be worth it. It could be, but it also might not be worth it, so blind guesses here just don't cut it. Hence, if you're going to worry about it, then you should be running some tests to see what the differences are.

Link to comment
Share on other sites

Re: Crons VS. Time Stamp

Yeah, I'm running test on it. And i see what you mean Floydian by it not giving health back without them being online. I didn't think about that yet. lol, See that why i started this post lol...

This post is just to get some gerneral ideas. I'm not really plaining on using this on my mccode game. I plan on useing this in another project I have.

Please keep the ideas and thoughts coming :)

And thanks Nyna and Hanif

Link to comment
Share on other sites

Re: Crons VS. Time Stamp

thats is what this question was...

what do you feel on the two options...

And I don't mean on Mccodes. lol....thats why i posted here and not in that section. lol..

I want to know what your thoughts are of it. ....Mostly if you think that a timestamp is faster?

Link to comment
Share on other sites

  • 2 weeks later...

Re: Crons VS. Time Stamp

 

For things like updating a user's energy or health, I'm not a big fan of using timestamps for that.

Suppose a user's health goes down to 0, and they don't log in for a day, their health will stay low and they would not be attackable for a long time.

 

I have thought about something on that......you could inplant a code that is included in the site that everyone uses...

JUST an example......

say you have a "main.php" which is where the main information of your game is at...so everyone gets this page included..

you could put something like this in there couldn't you?

 

$updatehealth = sprintf("UPDATE users SET health = '%u' WHERE health < '%u' ",
   ($maxhealth),
   ($maxhealth));
       mysql_query($updatehealth);

 

Now that would update peoples health with them offline......though you now have that running ever page load....

Link to comment
Share on other sites

Re: Crons VS. Time Stamp

I have been working on a timestamp cron implementation...

 

<?
$timesinceupdate = time() - $update;

if ($timesinceupdate>=300) {

$num_updates = floor($timesinceupdate / 300);
$result = mysql_query("SELECT id FROM `users`");

	while($line = mysql_fetch_assoc($result)) {
		$updates_user = // get user details
		$newenergy = $updates_user->energy + (($updates_user->maxenergy * .21) * $num_updates);

		$newenergy = ($newenergy > $updates_user->maxenergy) ? $updates_user->maxenergy : $newenergy;

		$newnerve = $updates_user->nerve + (($updates_user->maxnerve * .21) * $num_updates);

		$newnerve = ($newnerve > $updates_user->maxnerve) ? $updates_user->maxnerve : $newnerve;
	}
	$leftovertime = $timesinceupdate - (floor($timesinceupdate / 300) * 300);
if ($leftovertime>0) {

	$newupdate =  time() - $leftovertime;

	// update DB

}		
?>
Link to comment
Share on other sites

Re: Crons VS. Time Stamp

 

[sNIPPED]

say you have a "main.php" which is where the main information of your game is at...so everyone gets this page included..

you could put something like this in there couldn't you?

 

$updatehealth = sprintf("UPDATE users SET health = '%u' WHERE health < '%u' ",
   ($maxhealth),
   ($maxhealth));
       mysql_query($updatehealth);

 

Now that would update peoples health with them offline......though you now have that running ever page load....

 

I don't see how that is better than a cron? Health is normally a 5 minute cron, and I'd assume most games with a fairly active player base are going to have at least one person on loading pages. Putting a query like that on every page load is far far far more inefficient than a cron.

 

I'd go with this as a general rule:

If something only has to do with one person, keep it to that person's page loads. If it has to do with everyone, put it in a cron.

So, a query that targets all users is for crons, and a query that targets one user is for an individual's page loads.

Link to comment
Share on other sites

  • 1 year later...

Where would I put that piece of script you posted POG1?

I want to use timestamps instead of crons because I am building a new game on a free hosting site and they don't have crons. I have search how to replace crons with timestamps but I can find nothing about it. and just for the record, I know nothing about timestamps, so any help would be great :)

Link to comment
Share on other sites

I wanted to use something other than crons myself, As I really have just found out how much they rely on your server if you have a lot of members. I have found out about something called poormancrons that is something that you go to the pormancrons.install and it installs it on your game, I also figured out that it's not for mccodes but you can convert it to it..but it's a lot of work...

 

Now, I heard about timestamps, UNIX to be exact, I would love to use them, Someone told me to go to the site and set it up and I got a number like 9202853 or something similar to that but that is all that he told me and that is where I stopped, If someone can help me with this please PM me so we can set this up.

Thanks,

Ganjafreak.

Link to comment
Share on other sites

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