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.
Possible method for dealing without crons
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Possible method for dealing without crons
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.
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
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Possible method for dealing without crons
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.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.
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.
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Possible method for dealing without crons
Very nice! I actually did not know that myself, although it makes much more sense (due to issues of data alter corruption).hallsofvallhalla wrote: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.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.
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.
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
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Possible method for dealing without crons
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. 

- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Possible method for dealing without crons
They can be turned into one query, I just don't know how to do ithallsofvallhalla 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.

The indelible lord of tl;dr
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Possible method for dealing without crons
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.