Jump to content

Comparing old value to new value


zero_ZX

Recommended Posts

Hi,

The main idea is that I have a client running on certain desktops.

 

Each 5th minute the client sends and update to the web-server, increasing "tick" by one.

Tick start out as 0, so after 5 minutes ticket should be greater than 5.

If tick is not greater than 0 then do <code omitted>

 

I Guess I would need some kind of cronjob to complete this, but i'd love to avoid sessions & cookies at all costs, as the same server is checking the same tick but for different accounts..

 

Any suggestions are highly appreciated ^.^

 

Link to comment
Share on other sites

as the same server is checking the same tick but for different accounts..

So each update includes account information?

 

Keep a table in your database with an account identifier and tick count. SELECT when you get the tick, optionally do your stuff, and UPDATE when done. No cronjobs needed because you already have a script running when each update is received.

Link to comment
Share on other sites

Guess I wasn't clear enough, Ill try to elaborate:

As long as the client is running it's updating the tick with one.

Let's say I close the application and it stops at 30.

Next time the cron job calls the page it sees that it's 30 like last time, then it resets the tick to 0 and do some additional stuff.

 

So the main issue is that I want to do something when the script is not running.

Link to comment
Share on other sites

My advice would be to store two column for the ticks. One that gets updated by the client, the other gets updated by the CRON script checking.

 

Every time the CRON executes, check if Column1 = Column2 (no ticks have been added since the last execution), and set to 0, otherwise set Column2 to Column1

 

That can be done in a single query.

UPDATE `ticks` SET
  `user_ticks` = IF(`user_ticks` = `last_ticks`, 0, `user_ticks`),
  `last_ticks` = `user_ticks`

 

Where user_ticks is the ticks sent by the user, and last_ticks is the last ticks counted by the CRON.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.