Possible method for dealing without crons

Post all your tuts or request for tuts here.
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Possible method for dealing without crons

Post by hallsofvallhalla »

the query times are exactly that, query times through myadmin. Scripts however are a somewhat different story. While I am not going to say there is a huge time difference there is a significant delay in updates.

Try to use ajax to run a script but leave the delay to refresh the page at about .1 second. Even the fastest query will not execute the page and query fast enough, especially on a hosted server.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Possible method for dealing without crons

Post by Jackolantern »

AJAX really isn't a good comparison to straight PHP, because of AJAX's asynchronous nature. With the latency added in, we are likely talking about much larger sets of time. But for a PHP script to execute and a small one-row MySQL update, we are talking about a handful of milliseconds at worst. Go into the MySQL console and play around with a few small update queries, and it will tell you how long it took to complete. They are nearly trivial fractions of seconds.

While it is true that there could be two updates to start at the same time with the above method, because the script starts the action and completes it without any user action, additional scripts, etc., it is highly unlikely that such a clash would occur unless you had a very large player population. If that is the case (or to safe-guard for future scaling), just add in more consistency-checking logic to it. This was only meant to be a bare-bones explanation of the method.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Possible method for dealing without crons

Post by hallsofvallhalla »

Go into the MySQL console and play around with a few small update queries, and it will tell you how long it took to complete. They are nearly trivial fractions of seconds.
hehe before I ever started working with mysql and php thats the first thing I did. I spend a lot of time testing my own queries for games this way.

One thing I did not however think about because my head has been in the gutter the past few days is that mysql entries run in succession and not sim. The first person to run the script will alter it and everyone else will wait until that update is finished then their queries will go through. Therefore you are correct, I doubt you would have a issue.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Possible method for dealing without crons

Post by Jackolantern »

hallsofvallhalla wrote:
Go into the MySQL console and play around with a few small update queries, and it will tell you how long it took to complete. They are nearly trivial fractions of seconds.
hehe before I ever started working with mysql and php thats the first thing I did. I spend a lot of time testing my own queries for games this way.

One thing I did not however think about because my head has been in the gutter the past few days is that mysql entries run in succession and not sim. The first person to run the script will alter it and everyone else will wait until that update is finished then their queries will go through. Therefore you are correct, I doubt you would have a issue.
Very nice! I actually did not know that myself, although it makes much more sense (due to issues of data alter corruption).

However, the original psuedo-script I wrote in the OP uses two different scripts: one to check the time, and one to update. Do you mean only one SQL statement will go through at a time, or only one whole script? If it is the latter, then it would be fine, but if it was the former, there would need to be a bit more complex query to do it in one shot instead of two different queries. I know that they could be combined with SQL conditionals and sub-queries, but queries like those are a bit over my head at the moment.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Possible method for dealing without crons

Post by hallsofvallhalla »

eww yeah I didn't see that. Only one query at a time, so I would place the two queries as close together as possible. :)
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Possible method for dealing without crons

Post by Jackolantern »

hallsofvallhalla wrote:eww yeah I didn't see that. Only one query at a time, so I would place the two queries as close together as possible. :)
They can be turned into one query, I just don't know how to do it :P You have IF statements (edit: IF statements in SQL that is, not the PHP IF statements), subqueries, etc. at your disposal, and it is very possible to update a value only if a condition is true from a sub-query. The resident SQL expert at my old company used to do these types of queries all the time.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Possible method for dealing without crons

Post by hallsofvallhalla »

actually after re-reviewing your code it will work . Even if someone updates the time after someone else checks it, it still will only update the time to the correct time.
Post Reply

Return to “Tutorials”