Jump to content

Infinite Loops | Server Strain?


dreamBox

Recommended Posts

Hi all,

 

I am working on a project where I need to monitor accounts and suspend features associated with them if their deposited balance runs out.

 

To do this I'm thinking it might be best to have a script running with an infinite loop that constantly refreshes but I'm not sure what kind of strain this might put on the server.

 

The pseudocode would look something like this:

 

while (1) {
  For each row in database {
    If balance <= 0 {
       mysql query - account_status = suspended
    }
  }
}

Please note (obviously) this is psuedocode and not actual code.

 

I'm just concerned about how I would stop this script timing out, and what kind of impact it would have on server performance?

 

Is there any better way to do this?

 

Happy to discuss,

 

dB

Link to comment
Share on other sites

An infinite loop is definitely not a good option. this would be much better done by having the script scheduled to execute every minute (or whatever). This can be done via either Cron on Linux or Scedual Task on Windows.

Link to comment
Share on other sites

why repeatedly check rows that may have had no activity since the last check, when checking the balance whenever a row is updated may be easier and take less server time?

ie

A) query to update balance (this query should already contain some unique field value so as to only update a particular row)

B) query to check value of new balance - if balance <=0 - suspend

 

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.