my $dbh = DBI->connect($dsn, $user, $pass) or die "Can't connect to the DB: $DBI::errstr\n"; while($count == 0) { my $sth = $dbh->prepare("select * from collage_queue where `status` = 0"); $sth->execute or die "Couldn't execute statement: " . $sth->errstr; # Lock the entries $update = $dbh->prepare("update collage_queue set `lock`=1;"); $update->execute or die "Couldn't execute statement: " . $sth->errstr; while(@row = $sth->fetchrow_array()) { print `date` . ": "; # print "Result: perl collage.pl -query=" . $row[1]; $result = `perl collage.pl -query=$row[1]`; print "Result: $result\n"; $update = $dbh->prepare("update collage_queue set `result`=\"$result\", `status`=1,`lock`=0 where `id`=$row[0];"); $update->execute or die "Couldn't execute statement: " . $sth->errstr; } # Sleep for 5 seconds to prevent overusing the system resources sleep 5; }