Jump to content

Run every 6 seconds


amalesev

Recommended Posts

I am trying to write a script that is going to access a database, grab the newest picture from it, find the height and width, analyze the height and width to find which command (which is assigned to a variable) is the one to run, run that command in the terminal, and then access the database again 6 seconds later (new pictures are uploaded every 6 seconds) and re-run and enter the command for this new picture. I have most of this already done, the problem I am having is figuring out how to get this to run every 6 seconds for forever. (Yes it has to be every 6 seconds.) Can anyone help me?

 

Thanks in advance for the help!

Link to comment
Share on other sites

cron does not go down to that low a time period, does it?

 

I think you need to redesign the system if it has to be run every 6 seconds. Are you sure there is no other way? This is virtually continuously so maybe you write a service which looks for a file in a directory, once it finds it, it processes it and returns to looking for the next one after delay 1 second?. That way, whenever the file appears, it will be processed.

off the top of my head...

while (1 = 1) {

clearstatcache();

while( !file_exists(xxx)) {

    sleep for 1 second

}

// do processing

} // while 1 = 1

 

dont know if this would work, but you would have to test it.

Link to comment
Share on other sites

Are you sure there is no other way?

There is almost always more than one way to perform a task. The reason I suggested Cron Jobs is because the use the clock, rather than a timer, to determine when to run a task, allowing for greater consistency.

 

If you have access enough to the server to allow for scripts to run forever, you could also use the time() function to determine when to act.

$checktime = time();
while( TRUE ) {
  if( time() > $checktime ) {
    $checktime += 6;
    // perform actions
  }
}

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.