If I've got a script such as this:

$sql = "SELECT * FROM table WHERE Status='0'";
$query = mysql_query($sql);

    while ($row = mysql_fetch_array($query)) 
       $id = $row['ID'];


       if($process->send()) { //after sent
         mysql_query("UPDATE table 
                      SET Status ='1' 
                      WHERE ID = '$id'"); 

Therefore it will update each row when process is performed.But when I've a lot more than 10000 records using the Status='0', the update will end up slow .

Same with there much better method to update the record? I can not update with a single query since I have to know whether each process is performed or otherwise.


Add all effective ones for an array and just commit all individuals concurrently.

if ($process->send()) {
    $done[] = $id;

and a little later:

mysql_query('UPDATE table SET Status=1 WHERE ID IN ('.implode(',', $done).')');

With respect to the version of MySQL you're using you may consider establishing a function which has the process saved that method for you to offset this method towards the Database to ensure that it does not delay your script in running.

Documentation for Create Procedure/Create Function: http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html

When the UPDATE totally performing slow, you should use the reduced_PRIORITY keyword for MyISAM storage engine:



UPDATE LOW_PRIORITY SET Status = 1 WHERE id = someid;

Make a saved procedure for your code. It really works extremely fast