Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6651373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:00:12+00:00 2026-05-26T01:00:12+00:00

The below script is called every 5 seconds. The issue is that if the

  • 0

The below script is called every 5 seconds. The issue is that if the server is responding slow, one entry in “blog” can get selected twice in a row because the server hasn’t had time to set “done” to “1” yet. Is there an industry standard (or whatever you call it) way to prevent this from happening?

$result = mysql_query("SELECT * FROM blogs WHERE done=0 LIMIT 1");
$rows = mysql_num_rows($result); //If there are no entries in with done set to 0, that means we've done them all; reset all entries to 0.
if($rows == 0)
{
    mysql_query("UPDATE blogs SET done=0 WHERE done=1");
}
else
{
    while($row = mysql_fetch_array($result))
    {
        mysql_query("UPDATE blogs SET done=1 WHERE id=$row[id]");
        // Do stuff
    }
}

I think I could change it to

while($row = mysql_fetch_array($result))
{
      if($row['done'] == 1){ die; }
      mysql_query("UPDATE blogs SET done=1 WHERE id=$row[id]");
      //Do stuff
}

But will that really fix the problem? I would imagine there would be a better way that really prevents it from happening without a shadow of a doubt.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:00:12+00:00Added an answer on May 26, 2026 at 1:00 am
    $result = mysql_query("SELECT * FROM blogs WHERE done=0 LIMIT 1");
    $rows = mysql_num_rows($result); //If there are no entries in with done set to 0, that means we've done them all; reset all entries to 0.
    if($rows == 0)
    {
        mysql_query("UPDATE blogs SET done=0 WHERE done=1");
    }
    else
    {
        while($row = mysql_fetch_array($result))
        {
            mysql_query("UPDATE blogs SET done=1 WHERE id=$row[id] AND done=0");
            if(mysql_affected_rows() != 1)
                die();
            // Do stuff
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script called jobrunner.py that calls class methods in main.py. See below...
Consider the script below. It will launch two subprocesses, each one a CherryPy app
I have the below shell script in which sql file is called which has
The script below is called when saving my app's options page. All options are
The script below has a parameter called loadurl . The loadurl represents a page
Given the script below that fetches words in another language and makes a connection
The code below is placed in the header and called via php to every
I use the below script to queue build in TFS 2010 build server. This
I have tested the below script on a demo page which is not using
I've tried the below script but I am getting an error: dim cn, rs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.