php中的多线程数据库操作

php中的多线程数据库操作,php,multithreading,Php,Multithreading,我有一个名为domains的表。它有2亿行。我想验证那些域名。下面是我的代码。但是我想运行1000个线程,这样我就可以在一个线程中验证1000个域,因为我的表中有2亿行 for ($i=0; $i<=1000; $i++){ check_domains(); } function check_domains(){ $sql = "SELECT * FROM urls where status=0 limit 1"; $result = mysql_query ($s

我有一个名为domains的表。它有2亿行。我想验证那些域名。下面是我的代码。但是我想运行1000个线程,这样我就可以在一个线程中验证1000个域,因为我的表中有2亿行

for ($i=0; $i<=1000; $i++){
   check_domains();
}

function check_domains(){
    $sql = "SELECT * FROM urls where status=0 limit 1";
    $result = mysql_query ($sql);
    $row = mysql_fetch_array ($result);
    //some validation and pinging the domain.
    if ($validated){
         $sql = "update urls set status=1 where id=".$row['id'];
         $result = mysql_query ($sql);
    }
} 

对于($i=0;$i您可以在脚本中使用
pcntl_fork
来复制线程,并为每个子线程处理1000个条目

我建议使用pthreads:。此外,请使用
mysqli
PDO
而不是
mysql